[Python-checkins] r71201 - in python/branches/py3k-short-float-repr: Demo/distutils/test2to3 Demo/distutils/test2to3/setup.py Demo/distutils/test2to3/test Doc/c-api/arg.rst Doc/c-api/exceptions.rst Doc/c-api/import.rst Doc/c-api/long.rst Doc/distutils/setupscript.rst Doc/extending/extending.rst Doc/extending/newtypes.rst Doc/howto/regex.rst Doc/library/abc.rst Doc/library/aifc.rst Doc/library/asynchat.rst Doc/library/atexit.rst Doc/library/base64.rst Doc/library/bdb.rst Doc/library/binascii.rst Doc/library/collections.rst Doc/library/csv.rst Doc/library/datetime.rst Doc/library/email.header.rst Doc/library/functions.rst Doc/library/http.client.rst Doc/library/importlib.rst Doc/library/io.rst Doc/library/mmap.rst Doc/library/os.path.rst Doc/library/pickle.rst Doc/library/pickletools.rst Doc/library/random.rst Doc/library/shelve.rst Doc/library/time.rst Doc/library/unittest.rst Doc/library/urllib.error.rst Doc/library/urllib.request.rst Doc/license.rst Doc/reference/datamodel.rst Doc/whatsnew/3.1.rst Grammar/Grammar Include/bytesobject.h Include/code.h Include/compile.h Include/import.h Include/parsetok.h Include/patchlevel.h Include/pythonrun.h Include/unicodeobject.h Lib/__future__.py Lib/_abcoll.py Lib/_pyio.py Lib/_strptime.py Lib/bisect.py Lib/cgitb.py Lib/collections.py Lib/distutils/__init__.py Lib/distutils/cmd.py Lib/distutils/command/build_ext.py Lib/distutils/command/install_data.py Lib/distutils/command/install_headers.py Lib/distutils/command/register.py Lib/distutils/command/upload.py Lib/distutils/extension.py Lib/distutils/tests/support.py Lib/distutils/tests/test_build_ext.py Lib/distutils/tests/test_clean.py Lib/distutils/tests/test_config.py Lib/distutils/tests/test_install_data.py Lib/distutils/tests/test_install_headers.py Lib/distutils/tests/test_msvc9compiler.py Lib/distutils/tests/test_register.py Lib/distutils/tests/test_sdist.py Lib/distutils/tests/test_upload.py Lib/distutils/util.py Lib/email/generator.py Lib/email/test/test_email.py Lib/email/test/test_email_codecs.py Lib/email/test/test_email_codecs_renamed.py Lib/http/client.py Lib/http/cookies.py Lib/http/server.py Lib/idlelib/EditorWindow.py Lib/idlelib/NEWS.txt Lib/idlelib/PyShell.py Lib/idlelib/idlever.py Lib/idlelib/rpc.py Lib/idlelib/run.py Lib/importlib/_bootstrap.py Lib/importlib/test/import_/test_path.py Lib/importlib/test/source/test_abc_loader.py Lib/importlib/test/util.py Lib/io.py Lib/locale.py Lib/mailbox.py Lib/multiprocessing/queues.py Lib/site.py Lib/symtable.py Lib/test/buffer_tests.py Lib/test/regrtest.py Lib/test/support.py Lib/test/test___all__.py Lib/test/test_asynchat.py Lib/test/test_bz2.py Lib/test/test_collections.py Lib/test/test_crypt.py Lib/test/test_csv.py Lib/test/test_ctypes.py Lib/test/test_curses.py Lib/test/test_dbm.py Lib/test/test_dbm_gnu.py Lib/test/test_dbm_ndbm.py Lib/test/test_exceptions.py Lib/test/test_fcntl.py Lib/test/test_flufl.py Lib/test/test_fork1.py Lib/test/test_functools.py Lib/test/test_gc.py Lib/test/test_grp.py Lib/test/test_http_cookiejar.py Lib/test/test_http_cookies.py Lib/test/test_imp.py Lib/test/test_io.py Lib

eric.smith python-checkins at python.org
Sun Apr 5 01:04:27 CEST 2009


Author: eric.smith
Date: Sun Apr 5 01:04:14 2009
New Revision: 71201
Log:
Merged revisions 70733-71200 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
 r70736 | ronald.oussoren | 2009年03月30日 15:25:21 -0400 (2009年3月30日) | 10 lines
 
 Merged revisions 70735 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70735 | ronald.oussoren | 2009年03月30日 14:22:56 -0500 (2009年3月30日) | 3 lines
 
 Remove usage of the deprecated '-cString' and '+stringWithCString:' API's
 in PythonLauncher, replacing them with the correct counterparts.
 ........
................
 r70739 | ronald.oussoren | 2009年03月30日 15:39:14 -0400 (2009年3月30日) | 13 lines
 
 Merged revisions 70737 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70737 | ronald.oussoren | 2009年03月30日 14:34:51 -0500 (2009年3月30日) | 6 lines
 
 * Set a custom icon on the Python installer DMG
 * Remove last traces of "MacPython" 
 * Add options to build different flavors of the installer
 (still defaulting to a 2-way universal build that 
 runs on OSX 10.3)
 ........
................
 r70740 | ronald.oussoren | 2009年03月30日 15:51:09 -0400 (2009年3月30日) | 3 lines
 
 Enable "--with-computed-gotos" for the binary installer
 on OSX.
................
 r70742 | brett.cannon | 2009年03月30日 15:57:15 -0400 (2009年3月30日) | 5 lines
 
 Fix importlib.machinery.PathFinder.find_module() to essentially skip over None
 entries in sys.path_importer_cache. While this differs from semantics in how
 __import__ works, it prevents any implicit semantics from taking hold with
 users.
................
 r70745 | ronald.oussoren | 2009年03月30日 16:00:00 -0400 (2009年3月30日) | 9 lines
 
 Merged revisions 70741 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70741 | ronald.oussoren | 2009年03月30日 14:56:25 -0500 (2009年3月30日) | 2 lines
 
 Fixes issue 5270
 ........
................
 r70749 | ronald.oussoren | 2009年03月30日 16:05:35 -0400 (2009年3月30日) | 9 lines
 
 Merged revisions 70746 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70746 | ronald.oussoren | 2009年03月30日 15:02:08 -0500 (2009年3月30日) | 2 lines
 
 Fix for issue 13095
 ........
................
 r70750 | ronald.oussoren | 2009年03月30日 16:10:18 -0400 (2009年3月30日) | 2 lines
 
 Fix for issue 5558
................
 r70751 | guido.van.rossum | 2009年03月30日 16:34:57 -0400 (2009年3月30日) | 2 lines
 
 Thorough review of importlib docs. Reviewed by Brett himself.
................
 r70753 | georg.brandl | 2009年03月30日 17:21:05 -0400 (2009年3月30日) | 1 line
 
 Remove merging leftover.
................
 r70755 | brett.cannon | 2009年03月30日 17:30:26 -0400 (2009年3月30日) | 6 lines
 
 Make sure time.strptime only accepts strings (and document the fact like
 strftime). Already didn't accept bytes but make the check earlier. This also
 lifts the limitation of requiring ASCII.
 
 Closes issue #5236. Thanks Tennessee Leeuwenburg.
................
 r70760 | senthil.kumaran | 2009年03月30日 17:54:41 -0400 (2009年3月30日) | 3 lines
 
 Fix for Issue4962, issue4675.
................
 r70762 | guido.van.rossum | 2009年03月30日 18:01:35 -0400 (2009年3月30日) | 8 lines
 
 Issue #5604: non-ASCII characters in module name passed to
 imp.find_module() were converted to UTF-8 while the path is
 converted to the default filesystem encoding, causing nonsense.
 Thanks to Andrew Svetlov.
 
 (This time to the right branch. Will block duplicate merge to 3.0.2.)
................
 r70774 | jesse.noller | 2009年03月30日 18:59:27 -0400 (2009年3月30日) | 1 line
 
 finalize the queue to resolve test issue
................
 r70780 | barry.warsaw | 2009年03月30日 19:12:30 -0400 (2009年3月30日) | 4 lines
 
 "Port" the fix for issue 1974 from the trunk (2.7). Because Python 3.x does things much better, less changes are necessary.
 
 This also shoves test_email_codecs_rename.py onto test_email_codecs.py even though the test needs to be ported to Python 3.
................
 r70782 | ronald.oussoren | 2009年03月30日 19:16:10 -0400 (2009年3月30日) | 11 lines
 
 Merged revisions 70778 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70778 | ronald.oussoren | 2009年03月30日 18:10:35 -0500 (2009年3月30日) | 4 lines
 
 Fix issue #4865: add /Library/Python/2.7/site-packages to
 sys.path on OSX, to make it easier to share (some) installed 
 packages between the system install and a user install.
 ........
................
 r70786 | georg.brandl | 2009年03月30日 20:33:15 -0400 (2009年3月30日) | 1 line
 
 Add example for new copydir_run_2to3().
................
 r70787 | georg.brandl | 2009年03月30日 20:34:54 -0400 (2009年3月30日) | 1 line
 
 Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
................
 r70791 | jesse.noller | 2009年03月30日 23:25:07 -0400 (2009年3月30日) | 1 line
 
 merge 70783 to py3k
................
 r70794 | jesse.noller | 2009年03月30日 23:37:07 -0400 (2009年3月30日) | 1 line
 
 merge 70792 to py3k
................
 r70796 | brett.cannon | 2009年03月30日 23:58:04 -0400 (2009年3月30日) | 3 lines
 
 The message for the exception when time.strptime was passed something other
 than str did not output the type of the argument but the object itself.
................
 r70797 | georg.brandl | 2009年03月31日 00:16:10 -0400 (2009年3月31日) | 1 line
 
 Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
................
 r70806 | ronald.oussoren | 2009年03月31日 09:25:17 -0400 (2009年3月31日) | 11 lines
 
 Merged revisions 70802 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70802 | ronald.oussoren | 2009年03月31日 08:20:45 -0500 (2009年3月31日) | 4 lines
 
 Minor update to OSX build-installer script, needed
 to ensure that the build will succeed in a clean
 checkout and with a non-default deployment target.
 ........
................
 r70808 | hirokazu.yamamoto | 2009年03月31日 09:44:06 -0400 (2009年3月31日) | 9 lines
 
 Merged revisions 70800 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70800 | hirokazu.yamamoto | 2009年03月31日 22:13:05 +0900 | 1 line
 
 Issue #5387: Fixed mmap.move crash by integer overflow.
 ........
................
 r70815 | jeremy.hylton | 2009年03月31日 10:35:53 -0400 (2009年3月31日) | 12 lines
 
 Simplify the Request class. The basic components of the parsed
 Request are now available as public attributes, e.g. full_url and
 host. The accessor methods are deprecated. The implementation
 replace the complicated __getattr__ machinery with a _parse() method.
 
 The response from an HTTP request is now an HTTPResponse instance
 instead of an addinfourl() wrapper instance. The wrapper provided
 minimal extract functionality and was undocumented. The API of
 addinfourl() was preserved, except for close hooks, by adding a few
 methods and public attributes to the HTTPResponse class.
................
 r70816 | jeremy.hylton | 2009年03月31日 10:37:44 -0400 (2009年3月31日) | 2 lines
 
 Change email address.
................
 r70817 | jeremy.hylton | 2009年03月31日 10:38:13 -0400 (2009年3月31日) | 2 lines
 
 Document public attributes of urllib.request.Request.
................
 r70818 | jeremy.hylton | 2009年03月31日 10:40:19 -0400 (2009年3月31日) | 2 lines
 
 Update HTTPResponse documentation and add placeholder for HTTPMessage.
................
 r70823 | jeremy.hylton | 2009年03月31日 11:26:37 -0400 (2009年3月31日) | 29 lines
 
 Merged revisions 70801,70809 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 The merge ran into a lot of conflicts because dicts were replaced with
 sets in the Python 3 version of the symbol table.
 
 ........
 r70801 | jeremy.hylton | 2009年03月31日 09:17:03 -0400 (2009年3月31日) | 3 lines
 
 Add is_declared_global() which distinguishes between implicit and
 explicit global variables.
 ........
 r70809 | jeremy.hylton | 2009年03月31日 09:48:15 -0400 (2009年3月31日) | 14 lines
 
 Global statements from one function leaked into parallel functions.
 
 Re http://bugs.python.org/issue4315
 
 The symbol table used the same name dictionaries to recursively
 analyze each of its child blocks, even though the dictionaries are
 modified during analysis. The fix is to create new temporary
 dictionaries via the analyze_child_block(). The only information that
 needs to propagate back up is the names of the free variables.
 
 Add more comments and break out a helper function. This code doesn't
 get any easier to understand when you only look at it once a year.
 ........
................
 r70826 | georg.brandl | 2009年03月31日 11:48:12 -0400 (2009年3月31日) | 8 lines
 
 Blocked revisions 70825 via svnmerge
 
 ........
 r70825 | georg.brandl | 2009年03月31日 10:46:30 -0500 (Di, 31 Mär 2009) | 1 line
 
 #5566: fix versionadded from PyLong ssize_t functions.
 ........
................
 r70827 | georg.brandl | 2009年03月31日 11:49:02 -0400 (2009年3月31日) | 1 line
 
 #5566: remove duplicate entry.
................
 r70829 | georg.brandl | 2009年03月31日 11:52:41 -0400 (2009年3月31日) | 1 line
 
 #5548: do return the new module from PyMODINIT_FUNC functions.
................
 r70833 | jeremy.hylton | 2009年03月31日 12:37:16 -0400 (2009年3月31日) | 3 lines
 
 Make urllib use HTTP/1.1. It seems to work now, but hasn't been
 carefully tested.
................
 r70839 | georg.brandl | 2009年03月31日 12:55:13 -0400 (2009年3月31日) | 8 lines
 
 Blocked revisions 70838 via svnmerge
 
 ........
 r70838 | georg.brandl | 2009年03月31日 11:54:38 -0500 (Di, 31 Mär 2009) | 1 line
 
 #992207: document that the parser only accepts \\n newlines.
 ........
................
 r70840 | georg.brandl | 2009年03月31日 12:57:13 -0400 (2009年3月31日) | 1 line
 
 Forward-port of #992207 fix: document that the parser only accepts \\n newlines. (And remove a leftover footnote.)
................
 r70843 | kristjan.jonsson | 2009年03月31日 13:43:39 -0400 (2009年3月31日) | 2 lines
 
 get_file() no longer leaks a FILE structure. If given a file descriptor, it calls dup() to get a new handle. Then both the FILE object and the fd can be closed.
 This is important, because otherwise, the leaked FILE object will be closed on process exit, causing assertions on Windows, e.g. in the test_multiprocessing.py regression test.
................
 r70845 | kristjan.jonsson | 2009年03月31日 13:47:50 -0400 (2009年3月31日) | 1 line
 
 Fix a leaking "pathname" in import.c
................
 r70846 | raymond.hettinger | 2009年03月31日 13:51:51 -0400 (2009年3月31日) | 1 line
 
 Per the language summit, the optional fastpath imports should use from-import-star.
................
 r70853 | r.david.murray | 2009年03月31日 14:27:51 -0400 (2009年3月31日) | 10 lines
 
 Merged revisions 70779 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70779 | r.david.murray | 2009年03月30日 19:10:37 -0400 (2009年3月30日) | 3 lines
 
 Actually suppress warnings in test_at_least_import_untested_modules
 inside the catch_warnings context manager.
 ........
................
 r70860 | georg.brandl | 2009年03月31日 14:40:41 -0400 (2009年3月31日) | 8 lines
 
 Blocked revisions 70858 via svnmerge
 
 ........
 r70858 | georg.brandl | 2009年03月31日 13:38:56 -0500 (Di, 31 Mär 2009) | 1 line
 
 #5241: document missing U in regex howto.
 ........
................
 r70861 | georg.brandl | 2009年03月31日 14:41:03 -0400 (2009年3月31日) | 1 line
 
 #5241: document missing A in regex howto.
................
 r70862 | jesse.noller | 2009年03月31日 14:48:42 -0400 (2009年3月31日) | 13 lines
 
 Merged revisions 70849,70852 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70849 | jesse.noller | 2009年03月31日 13:12:35 -0500 (2009年3月31日) | 1 line
 
 Apply patch for netbsd multiprocessing support
 ........
 r70852 | jesse.noller | 2009年03月31日 13:27:14 -0500 (2009年3月31日) | 1 line
 
 missed the news/acks for netbsd patch
 ........
................
 r70863 | georg.brandl | 2009年03月31日 14:56:38 -0400 (2009年3月31日) | 1 line
 
 #1717: fix-up docs for comparison in newtypes document.
................
 r70865 | georg.brandl | 2009年03月31日 15:06:37 -0400 (2009年3月31日) | 1 line
 
 Add missing label.
................
 r70884 | hirokazu.yamamoto | 2009年03月31日 16:43:56 -0400 (2009年3月31日) | 9 lines
 
 Merged revisions 70879 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70879 | hirokazu.yamamoto | 2009年04月01日 05:14:04 +0900 | 1 line
 
 Issue #5387: Fixed mmap.move crash by integer overflow. (take2)
 ........
................
 r70898 | tarek.ziade | 2009年03月31日 17:37:16 -0400 (2009年3月31日) | 29 lines
 
 Merged revisions 70886,70888-70892 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70886 | tarek.ziade | 2009年03月31日 15:50:59 -0500 (2009年3月31日) | 1 line
 
 added tests for the clean command
 ........
 r70888 | tarek.ziade | 2009年03月31日 15:53:13 -0500 (2009年3月31日) | 1 line
 
 more tests for the register command
 ........
 r70889 | tarek.ziade | 2009年03月31日 15:53:55 -0500 (2009年3月31日) | 1 line
 
 more tests for the upload command
 ........
 r70890 | tarek.ziade | 2009年03月31日 15:54:38 -0500 (2009年3月31日) | 1 line
 
 added test to the install_data command
 ........
 r70891 | tarek.ziade | 2009年03月31日 15:55:21 -0500 (2009年3月31日) | 1 line
 
 added tests to the install_headers command
 ........
 r70892 | tarek.ziade | 2009年03月31日 15:56:11 -0500 (2009年3月31日) | 1 line
 
 making sdist and config test silents
 ........
................
 r70913 | jesse.noller | 2009年03月31日 18:36:44 -0400 (2009年3月31日) | 9 lines
 
 Merged revisions 70908 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70908 | jesse.noller | 2009年03月31日 17:20:35 -0500 (2009年3月31日) | 1 line
 
 Issue 5619: Pass MS CRT debug flags into subprocesses
 ........
................
 r70914 | tarek.ziade | 2009年03月31日 18:37:55 -0400 (2009年3月31日) | 9 lines
 
 Merged revisions 70910 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70910 | tarek.ziade | 2009年03月31日 17:27:23 -0500 (2009年3月31日) | 1 line
 
 #5583 Added optional Extensions in Distutils
 ........
................
 r70917 | martin.v.loewis | 2009年03月31日 18:42:41 -0400 (2009年3月31日) | 2 lines
 
 Readd -n.
................
 r70921 | georg.brandl | 2009年03月31日 18:46:50 -0400 (2009年3月31日) | 1 line
 
 Run 2to3 over new script.
................
 r70924 | tarek.ziade | 2009年03月31日 18:50:54 -0400 (2009年3月31日) | 13 lines
 
 Merged revisions 70920,70922 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70920 | tarek.ziade | 2009年03月31日 17:44:10 -0500 (2009年3月31日) | 1 line
 
 catching msvc9compiler error as well
 ........
 r70922 | tarek.ziade | 2009年03月31日 17:47:01 -0500 (2009年3月31日) | 1 line
 
 fixed the test for win32 CompileError
 ........
................
 r70925 | raymond.hettinger | 2009年03月31日 18:52:48 -0400 (2009年3月31日) | 1 line
 
 Improve examples for collections.deque()
................
 r70928 | benjamin.peterson | 2009年03月31日 19:11:32 -0400 (2009年3月31日) | 1 line
 
 fix TextIOWrapper.read() when the buffer is not readable #5628
................
 r70929 | r.david.murray | 2009年03月31日 19:16:50 -0400 (2009年3月31日) | 43 lines
 
 Merged revisions 70734,70775,70856,70874,70876-70877 via svnmerge
 
 ........
 r70734 | r.david.murray | 2009年03月30日 15:04:00 -0400 (2009年3月30日) | 7 lines
 
 Add import_function method to test.test_support, and modify a number of
 tests that expect to be skipped if imports fail or functions don't
 exist to use import_function and import_module. The ultimate goal is
 to change regrtest to not skip automatically on ImportError. Checking
 in now to make sure the buldbots don't show any errors on platforms
 I can't direct test on.
 ........
 r70775 | r.david.murray | 2009年03月30日 19:05:48 -0400 (2009年3月30日) | 4 lines
 
 Change more tests to use import_module for the modules that
 should cause tests to be skipped. Also rename import_function
 to the more descriptive get_attribute and add a docstring.
 ........
 r70856 | r.david.murray | 2009年03月31日 14:32:17 -0400 (2009年3月31日) | 7 lines
 
 A few more test skips via import_module, and change import_module to 
 return the error message produced by importlib, so that if an import 
 in the package whose import is being wrapped is what failed the skip 
 message will contain the name of that module instead of the name of the 
 wrapped module. Also fixed formatting of some previous comments. 
 ........
 r70874 | r.david.murray | 2009年03月31日 15:33:15 -0400 (2009年3月31日) | 5 lines
 
 Improve test_support.import_module docstring, remove
 deprecated flag from get_attribute since it isn't likely
 to do anything useful.
 ........
 r70876 | r.david.murray | 2009年03月31日 15:49:15 -0400 (2009年3月31日) | 4 lines
 
 Remove the regrtest check that turns any ImportError into a skipped test.
 Hopefully all modules whose imports legitimately result in a skipped
 test have been properly wrapped by the previous commits.
 ........
 r70877 | r.david.murray | 2009年03月31日 15:57:24 -0400 (2009年3月31日) | 2 lines
 
 Add NEWS entry for regrtest change.
 ........
................
 r70932 | r.david.murray | 2009年03月31日 19:50:31 -0400 (2009年3月31日) | 10 lines
 
 Merged revisions 70930 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70930 | r.david.murray | 2009年03月31日 19:45:39 -0400 (2009年3月31日) | 3 lines
 
 Fix Windows test skip error revealed by buildbot. Also a comment spelling
 correction in a previously fixed test.
 ........
................
 r70935 | jeremy.hylton | 2009年03月31日 22:35:56 -0400 (2009年3月31日) | 2 lines
 
 An HTTPResponse is, by its nature, readable.
................
 r70937 | brett.cannon | 2009年03月31日 23:35:20 -0400 (2009年3月31日) | 1 line
 
 Rip out a useless method that the superclass implements properly.
................
 r70938 | r.david.murray | 2009年03月31日 23:42:00 -0400 (2009年3月31日) | 11 lines
 
 Merged revisions 70936 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70936 | r.david.murray | 2009年03月31日 23:21:43 -0400 (2009年3月31日) | 4 lines
 
 Fix issue 2522. locale.format now checks that it is passed
 exactly one pattern, which avoids mysterious errors where it
 had seemed to fail to do localization.
 ........
................
 r70941 | jack.diederich | 2009年04月01日 00:27:09 -0400 (2009年4月01日) | 9 lines
 
 Merged revisions 70931 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70931 | jack.diederich | 2009年03月31日 19:46:48 -0400 (2009年3月31日) | 1 line
 
 #5228: add pickle support to functools.partial
 ........
................
 r70942 | georg.brandl | 2009年04月01日 00:27:47 -0400 (2009年4月01日) | 8 lines
 
 Merged revisions 70940 via svnmerge
 
 ........
 r70940 | georg.brandl | 2009年03月31日 23:21:14 -0500 (Di, 31 Mär 2009) | 2 lines
 
 The SimpleXMLRPCServer's CGI handler now runs like a pony.
 ........
................
 r70943 | georg.brandl | 2009年04月01日 00:28:33 -0400 (2009年4月01日) | 8 lines
 
 Merged revisions 70940 via svnmerge
 
 ........
 r70940 | georg.brandl | 2009年03月31日 23:21:14 -0500 (Di, 31 Mär 2009) | 2 lines
 
 The SimpleXMLRPCServer's CGI handler now runs like a pony.
 ........
................
 r70945 | brett.cannon | 2009年04月01日 01:08:41 -0400 (2009年4月01日) | 2 lines
 
 The BDFL has retired! Long live the FLUFL (Friendly Language Uncle For Life)!
................
 r70948 | kristjan.jonsson | 2009年04月01日 07:28:47 -0400 (2009年4月01日) | 1 line
 
 Allow skipping of regression tests not supported on windows. This reduces noise in the regression test suite for py3k on Windows.
................
 r70952 | ronald.oussoren | 2009年04月01日 10:59:59 -0400 (2009年4月01日) | 3 lines
 
 Fix typo in configure line that caused the build installer
 to not use the right LDFLAGS settings.
................
 r70955 | georg.brandl | 2009年04月01日 11:53:15 -0400 (2009年4月01日) | 1 line
 
 #5636: fix next -> __next__ in csv reader docs.
................
 r70957 | brett.cannon | 2009年04月01日 12:06:01 -0400 (2009年4月01日) | 12 lines
 
 Merged revisions 70956 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70956 | brett.cannon | 2009年04月01日 09:00:34 -0700 (2009年4月01日) | 5 lines
 
 The cgitb module had imports in its functions. This can cause deadlock with the
 import lock if called from within a thread that was triggered by an import.
 
 Partially fixes issue #1665206.
 ........
................
 r70959 | r.david.murray | 2009年04月01日 12:39:21 -0400 (2009年4月01日) | 2 lines
 
 Remove redundant import of tkinter.
................
 r70966 | brett.cannon | 2009年04月01日 14:13:07 -0400 (2009年4月01日) | 12 lines
 
 Merged revisions 70965 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70965 | brett.cannon | 2009年04月01日 11:03:59 -0700 (2009年4月01日) | 5 lines
 
 _warnings was importing itself to get an attribute. That's bad if warnings gets
 called in a thread that was spawned by an import itself.
 
 Last part to close #1665206.
 ........
................
 r70974 | raymond.hettinger | 2009年04月01日 15:05:50 -0400 (2009年4月01日) | 1 line
 
 Issue #5647: MutableSet.__iand__() no longer mutates self during iteration.
................
 r70976 | brett.cannon | 2009年04月01日 16:01:47 -0400 (2009年4月01日) | 11 lines
 
 Merged revisions 70975 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70975 | brett.cannon | 2009年04月01日 12:57:10 -0700 (2009年4月01日) | 4 lines
 
 test_logging was blindly clearing the warnings filter. This caused
 PendingDeprecationWarnings to be spewed all over by unittest.failIf*(). Fix
 moves over to using warnings.catch_warning to protect the warnings filter.
 ........
................
 r70978 | senthil.kumaran | 2009年04月01日 16:20:43 -0400 (2009年4月01日) | 3 lines
 
 Fix for issue5040. Adding support for unicode message passing and tests for unicode message and test for Content-Length.
................
 r70982 | brett.cannon | 2009年04月01日 16:27:29 -0400 (2009年4月01日) | 10 lines
 
 Merged revisions 70979 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70979 | brett.cannon | 2009年04月01日 13:25:48 -0700 (2009年4月01日) | 3 lines
 
 test_warnings ironically had a single test that was not protecting the warnings
 filter and was resetting it.
 ........
................
 r70983 | benjamin.peterson | 2009年04月01日 16:38:13 -0400 (2009年4月01日) | 1 line
 
 barry has already been causing test breakage
................
 r70984 | brett.cannon | 2009年04月01日 16:47:14 -0400 (2009年4月01日) | 1 line
 
 Add some clarification to the importlib docs.
................
 r70987 | jesse.noller | 2009年04月01日 16:51:28 -0400 (2009年4月01日) | 9 lines
 
 Merged revisions 70953 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70953 | hirokazu.yamamoto | 2009年04月01日 10:13:52 -0500 (2009年4月01日) | 1 line
 
 Fixed compile error on windows.
 ........
................
 r70988 | raymond.hettinger | 2009年04月01日 16:52:13 -0400 (2009年4月01日) | 1 line
 
 Add link to an alternative generator with a long-period.
................
 r70996 | benjamin.peterson | 2009年04月01日 17:22:20 -0400 (2009年4月01日) | 13 lines
 
 Merged revisions 70992,70995 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70992 | georg.brandl | 2009年04月01日 16:00:55 -0500 (2009年4月01日) | 1 line
 
 #4572: add SEEK_* values as constants in io.py.
 ........
 r70995 | benjamin.peterson | 2009年04月01日 16:12:54 -0500 (2009年4月01日) | 1 line
 
 add seek constants to __all__
 ........
................
 r71000 | r.david.murray | 2009年04月01日 18:37:58 -0400 (2009年4月01日) | 10 lines
 
 Merged revisions 70997 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70997 | r.david.murray | 2009年04月01日 17:26:18 -0400 (2009年4月01日) | 3 lines
 
 Add tests checking the CSV module's ability to handle
 embedded newlines in quoted field values.
 ........
................
 r71002 | georg.brandl | 2009年04月01日 19:07:29 -0400 (2009年4月01日) | 1 line
 
 #5656: detect correct encoding of files when reporting coverage in trace.py, and ignore files in the temporary directory when reporting.
................
 r71005 | brett.cannon | 2009年04月01日 19:26:47 -0400 (2009年4月01日) | 1 line
 
 Add a meta path importer example.
................
 r71007 | brett.cannon | 2009年04月01日 19:36:48 -0400 (2009年4月01日) | 1 line
 
 Explain a little about the explanation.
................
 r71012 | benjamin.peterson | 2009年04月01日 20:24:00 -0400 (2009年4月01日) | 1 line
 
 fix markup
................
 r71013 | benjamin.peterson | 2009年04月01日 20:33:55 -0400 (2009年4月01日) | 1 line
 
 make 'c' only accept bytes and 'C' only unicode #5499
................
 r71015 | benjamin.peterson | 2009年04月01日 21:03:26 -0400 (2009年4月01日) | 1 line
 
 add SEEK_ constants to _pyio
................
 r71016 | benjamin.peterson | 2009年04月01日 21:13:40 -0400 (2009年4月01日) | 9 lines
 
 Merged revisions 71014 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r71014 | benjamin.peterson | 2009年04月01日 20:03:17 -0500 (2009年4月01日) | 1 line
 
 handle SEEK_ constants in test_io
 ........
................
 r71017 | benjamin.peterson | 2009年04月01日 21:14:45 -0400 (2009年4月01日) | 1 line
 
 add io and _pyio to test___all__
................
 r71018 | benjamin.peterson | 2009年04月01日 21:50:37 -0400 (2009年4月01日) | 1 line
 
 fix ref leaks
................
 r71020 | benjamin.peterson | 2009年04月01日 22:27:20 -0400 (2009年4月01日) | 1 line
 
 rewrite error handling to make sense
................
 r71021 | benjamin.peterson | 2009年04月01日 22:27:56 -0400 (2009年4月01日) | 1 line
 
 remove unused variable
................
 r71027 | georg.brandl | 2009年04月01日 22:56:10 -0400 (2009年4月01日) | 2 lines
 
 First batch of signature documentation changes; using default argument syntax where applicable.
................
 r71030 | senthil.kumaran | 2009年04月01日 23:02:03 -0400 (2009年4月01日) | 3 lines
 
 Fixing the issue4860. Escaping the embedded '"' in the js_output method of Morsel class.
................
 r71034 | brett.cannon | 2009年04月01日 23:41:46 -0400 (2009年4月01日) | 13 lines
 
 Merged revisions 71031 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r71031 | brett.cannon | 2009年04月01日 20:17:39 -0700 (2009年4月01日) | 6 lines
 
 PyImport_AppendInittab() took a char * as a first argument even though that
 string was stored beyond the life of the call. Changed the signature to be
 const char * to help make this point.
 
 Closes issue #1419652.
 ........
................
 r71038 | r.david.murray | 2009年04月02日 00:50:03 -0400 (2009年4月02日) | 9 lines
 
 
 Clarify that datetime strftime does not produce leap seconds and datetime
 strptime does not accept it in the strftime behavior section of the
 datetime docs.
 
 Closes issue 2568.
 
 Porting by hand since svnmerge disclaims all knowledge of the trunk commit.
................
 r71042 | brett.cannon | 2009年04月02日 01:17:54 -0400 (2009年4月02日) | 5 lines
 
 Check that on a platform that is expected to have a case-insensitive filesystem
 that is in fact the case.
 
 Closes issue #5442.
................
 r71045 | hyeshik.chang | 2009年04月02日 06:33:16 -0400 (2009年4月02日) | 4 lines
 
 Issue #5640: Fix _multibytecodec so that CJK codecs don't repeat
 error replacement returned by codec error callbacks twice in
 IncrementalEncoder and StreamWriter.
................
 r71053 | brett.cannon | 2009年04月02日 11:32:07 -0400 (2009年4月02日) | 1 line
 
 Give a more informative message on an importlib test upon failure.
................
 r71054 | brett.cannon | 2009年04月02日 11:35:09 -0400 (2009年4月02日) | 1 line
 
 Make a test in importlib have a more robust test value.
................
 r71057 | brett.cannon | 2009年04月02日 13:54:43 -0400 (2009年4月02日) | 5 lines
 
 importlib.test.source.test_abc_loader was making a bad assumption that all file
 paths used '/' as a path separator.
 
 Fixes issue #5646.
................
 r71061 | mark.dickinson | 2009年04月02日 14:41:40 -0400 (2009年4月02日) | 2 lines
 
 Rewrap some long lines.
................
 r71063 | brett.cannon | 2009年04月02日 14:57:15 -0400 (2009年4月02日) | 1 line
 
 r71034 somehow deleted all of the metadata for svnmerge. This is my attempt to fix my mistake.
................
 r71064 | brett.cannon | 2009年04月02日 15:02:06 -0400 (2009年4月02日) | 1 line
 
 A fix for the fix for the svnmerge metadata.
................
 r71066 | r.david.murray | 2009年04月02日 15:21:26 -0400 (2009年4月02日) | 2 lines
 
 A fix for Brett's fix for his fix. I think we got it right this time.
................
 r71067 | r.david.murray | 2009年04月02日 15:44:43 -0400 (2009年4月02日) | 13 lines
 
 In 3k this becomes an items() call.
 
 Merged revisions 71046 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r71046 | r.david.murray | 2009年04月02日 10:05:35 -0400 (2009年4月02日) | 4 lines
 
 Add missing iteritems() call to the for loop in mailbox.MH.get_message().
 
 Fixes issue2625.
 ........
................
 r71071 | antoine.pitrou | 2009年04月02日 17:42:24 -0400 (2009年4月02日) | 8 lines
 
 Blocked revisions 71070 via svnmerge
 
 ........
 r71070 | antoine.pitrou | 2009年04月02日 23:18:34 +0200 (jeu., 02 avril 2009) | 3 lines
 
 Issue #2396: backport the memoryview object.
 ........
................
 r71074 | raymond.hettinger | 2009年04月02日 18:31:59 -0400 (2009年4月02日) | 4 lines
 
 Have namedtuple's field renamer assign names that
 are consistent with the corresponding tuple index.
................
 r71076 | raymond.hettinger | 2009年04月02日 18:37:59 -0400 (2009年4月02日) | 1 line
 
 Update docs for namedtuple's renaming change.
................
 r71079 | raymond.hettinger | 2009年04月02日 22:45:36 -0400 (2009年4月02日) | 3 lines
 
 Localize the function lookup in timeit.
................
 r71084 | alexandre.vassalotti | 2009年04月03日 00:17:41 -0400 (2009年4月03日) | 3 lines
 
 Update a comment about why the __module__ can sometime be NULL.
 Initialize last_string and arg member of Unpickler.
................
 r71087 | raymond.hettinger | 2009年04月03日 01:47:33 -0400 (2009年4月03日) | 1 line
 
 Fix typo.
................
 r71088 | alexandre.vassalotti | 2009年04月03日 02:07:29 -0400 (2009年4月03日) | 2 lines
 
 Remove old reference to cPickle.
................
 r71089 | alexandre.vassalotti | 2009年04月03日 02:13:29 -0400 (2009年4月03日) | 2 lines
 
 Add more examples in pickle documentation.
................
 r71090 | alexandre.vassalotti | 2009年04月03日 02:19:27 -0400 (2009年4月03日) | 2 lines
 
 Emphasize that Unpickler.memo is not necessarily a dict.
................
 r71091 | alexandre.vassalotti | 2009年04月03日 02:38:02 -0400 (2009年4月03日) | 4 lines
 
 Optimize slicing of bytes and bytearray by avoiding useless copying.
 
 This restores the behavior that was present in Python 2.x.
................
 r71092 | alexandre.vassalotti | 2009年04月03日 02:58:20 -0400 (2009年4月03日) | 8 lines
 
 Undocument the existence of the memo attribute and its main use-case.
 
 Apparently, Guido don't like this behavior. [1] I also agree that the memo
 should be left as an implementation detail.
 
 [1]: http://mail.python.org/pipermail/python-dev/2009-March/086809.html
................
 r71093 | alexandre.vassalotti | 2009年04月03日 03:16:55 -0400 (2009年4月03日) | 8 lines
 
 Make http.server main program nicer for interactive use.
 Remove unreachable calls to test().
 
 This restores the behavior of SimpleHTTPServer, where a user could
 type "python -m SimpleHTTPServer" and get a simple server for sharing
 files. Now, you can do the same thing with "python3 -m http.server".
................
 r71095 | eric.smith | 2009年04月03日 07:19:31 -0400 (2009年4月03日) | 1 line
 
 Removed mixed tabs and whitespace.
................
 r71096 | eric.smith | 2009年04月03日 10:45:06 -0400 (2009年4月03日) | 9 lines
 
 Added ',' thousands grouping to int.__format__. See PEP 378.
 
 This is incomplete, but I want to get some version into the next alpha. I am still working on:
 Documentation.
 More tests.
 Implement for floats.
 
 In addition, there's an existing bug with 'n' formatting that carries forward to thousands grouping (issue 5515).
................
 r71107 | benjamin.peterson | 2009年04月03日 18:18:11 -0400 (2009年4月03日) | 1 line
 
 Py_BuildValue's 'c' code should use byte strings #5666
................
 r71108 | benjamin.peterson | 2009年04月03日 18:22:42 -0400 (2009年4月03日) | 1 line
 
 update NEWS
................
 r71109 | benjamin.peterson | 2009年04月03日 18:23:43 -0400 (2009年4月03日) | 1 line
 
 os.path.listdir -> os.listdir
................
 r71110 | eric.smith | 2009年04月03日 18:25:33 -0400 (2009年4月03日) | 1 line
 
 Added Misc/NEWS entry for PEP 378.
................
 r71112 | benjamin.peterson | 2009年04月03日 19:47:26 -0400 (2009年4月03日) | 1 line
 
 fix naming
................
 r71113 | benjamin.peterson | 2009年04月03日 19:57:05 -0400 (2009年4月03日) | 1 line
 
 fix this test
................
 r71114 | benjamin.peterson | 2009年04月03日 20:46:15 -0400 (2009年4月03日) | 1 line
 
 fix name
................
 r71115 | benjamin.peterson | 2009年04月03日 21:21:56 -0400 (2009年4月03日) | 1 line
 
 fix name again
................
 r71116 | r.david.murray | 2009年04月03日 21:38:38 -0400 (2009年4月03日) | 10 lines
 
 Update documentation for csv module to reflect changes in code,
 specifically that it now expects unicode input (and therefore the
 paragraph about it not handling unicode is deleted, as well as
 the 'how to handle unicode' examples) and that files should
 be opened with "newline=''" instead of binary mode. Also removed
 unused BytesIO import from test_csv.
 
 This addresses issue 4847.
................
 r71118 | benjamin.peterson | 2009年04月03日 23:37:26 -0400 (2009年4月03日) | 733 lines
 
 Blocked revisions 70176,70178,70197,70261,70267,70271,70273,70286,70290,70292-70293,70295-70296,70298,70300,70305,70315,70319,70368,70443,70454,70463,70466,70470-70473,70475,70477,70479,70485,70531,70533,70538,70544,70552-70553,70564,70601,70651,70672,70702,70711-70714,70716,70719,70723,70734,70747,70757,70764-70765,70768-70773,70775-70777,70788-70789,70807,70821,70824-70825,70828,70830,70832,70836-70838,70842,70844,70851,70855-70858,70864,70866-70874,70876-70878,70883,70885,70893-70894,70896-70897,70901-70908,70912,70915,70918,70927,70933-70934,70939-70940,70944,70951,70958,70960,70962-70964,70968-70969,70980-70981,70986,70993-70994,70998,71001,71004,71006,71008-71011,71019,71022-71024,71026,71029,71031-71033,71036-71037,71041,71043,71056,71058-71059,71070,71073,71075,71078 via svnmerge
 
 ........
 r70176 | ronald.oussoren | 2009年03月04日 15:35:05 -0600 (2009年3月04日) | 2 lines
 
 Fixes issues 3883 and 5194
 ........
 r70178 | ronald.oussoren | 2009年03月04日 16:49:36 -0600 (2009年3月04日) | 2 lines
 
 Fix for issue #1113328.
 ........
 r70197 | jesus.cea | 2009年03月05日 13:37:37 -0600 (2009年3月05日) | 1 line
 
 Minor bsddb documentation glitch
 ........
 r70261 | raymond.hettinger | 2009年03月09日 06:31:39 -0500 (2009年3月09日) | 1 line
 
 Issue 5443: Fix typo.
 ........
 r70267 | raymond.hettinger | 2009年03月09日 06:57:29 -0500 (2009年3月09日) | 1 line
 
 Add consume() recipe to itertools docs.
 ........
 r70271 | raymond.hettinger | 2009年03月09日 07:56:23 -0500 (2009年3月09日) | 1 line
 
 Add cross-reference to the collections docs.
 ........
 r70273 | georg.brandl | 2009年03月09日 09:25:07 -0500 (2009年3月09日) | 2 lines
 
 #5458: add a note when we started to raise RuntimeErrors.
 ........
 r70286 | raymond.hettinger | 2009年03月09日 19:06:05 -0500 (2009年3月09日) | 1 line
 
 Fix markup.
 ........
 r70290 | raymond.hettinger | 2009年03月09日 20:07:30 -0500 (2009年3月09日) | 1 line
 
 Update url for the spec.
 ........
 r70292 | raymond.hettinger | 2009年03月09日 23:40:24 -0500 (2009年3月09日) | 1 line
 
 Clarify the meaning of normal and subnormal.
 ........
 r70293 | raymond.hettinger | 2009年03月09日 23:49:21 -0500 (2009年3月09日) | 1 line
 
 Add a version tag to the decimal module.
 ........
 r70295 | raymond.hettinger | 2009年03月10日 03:16:05 -0500 (2009年3月10日) | 1 line
 
 Update the decimal FAQ for the from_float() classmethod and improve the recipe for remove_exponent() to make it cut and pasteable.
 ........
 r70296 | raymond.hettinger | 2009年03月10日 04:31:48 -0500 (2009年3月10日) | 1 line
 
 Small optimization for corner case where maxlen==0.
 ........
 r70298 | raymond.hettinger | 2009年03月10日 07:50:59 -0500 (2009年3月10日) | 1 line
 
 For collections.deque() objects, expose the maxlen parameter as a read-only attribute.
 ........
 r70300 | raymond.hettinger | 2009年03月10日 08:04:30 -0500 (2009年3月10日) | 1 line
 
 Fix typo.
 ........
 r70305 | brett.cannon | 2009年03月10日 23:51:06 -0500 (2009年3月10日) | 5 lines
 
 Require implementations for warnings.showwarning() support the 'line' argument.
 Was a DeprecationWarning for not supporting it since Python 2.6.
 
 Closes issue #3652.
 ........
 r70315 | raymond.hettinger | 2009年03月11日 19:25:03 -0500 (2009年3月11日) | 1 line
 
 Add reference to solution for a commonly asked question.
 ........
 r70319 | raymond.hettinger | 2009年03月11日 19:31:58 -0500 (2009年3月11日) | 1 line
 
 Issue 5477: Fix buglet in the itertools documentation.
 ........
 r70368 | eric.smith | 2009年03月14日 09:37:38 -0500 (2009年3月14日) | 1 line
 
 Unicode format tests weren't actually testing unicode. This was probably due to the original backport from py3k.
 ........
 r70443 | bob.ippolito | 2009年03月17日 18:19:00 -0500 (2009年3月17日) | 1 line
 
 merge json library with simplejson 2.0.9 (issue 4136)
 ........
 r70454 | mark.dickinson | 2009年03月18日 11:07:26 -0500 (2009年3月18日) | 9 lines
 
 Issue 4474: On platforms with sizeof(wchar_t) == 4 and
 sizeof(Py_UNICODE) == 2, PyUnicode_FromWideChar now converts
 each character outside the BMP to the appropriate surrogate pair.
 
 Thanks Victor Stinner for the patch.
 
 (backport of r70452 from py3k to trunk)
 ........
 r70463 | benjamin.peterson | 2009年03月18日 15:52:15 -0500 (2009年3月18日) | 1 line
 
 fix strange errors when setting attributes on tracebacks #4034
 ........
 r70466 | raymond.hettinger | 2009年03月18日 17:13:20 -0500 (2009年3月18日) | 1 line
 
 Use mixin methods where possible. (2.7 only -- these don't all exist in 3.0)
 ........
 r70470 | raymond.hettinger | 2009年03月19日 10:21:10 -0500 (2009年3月19日) | 6 lines
 
 Improve implementation with better underlying data structure
 for O(1) deletions. Big-Oh performance now the same as regular
 dictionaries. Uses a doubly-linked list instead of a list/seq
 to track insertion order.
 ........
 r70471 | raymond.hettinger | 2009年03月19日 14:19:03 -0500 (2009年3月19日) | 3 lines
 
 Issue 5381: Add object_pairs_hook to the json module.
 ........
 r70472 | raymond.hettinger | 2009年03月19日 14:24:43 -0500 (2009年3月19日) | 1 line
 
 Silence a compiler warning.
 ........
 r70473 | raymond.hettinger | 2009年03月19日 14:59:58 -0500 (2009年3月19日) | 6 lines
 
 * Add clearer comment to initialization code.
 * Add optional argument to popitem() -- modeled
 after Anthon van der Neut's C version.
 * Fix method markup in docs.
 ........
 r70475 | raymond.hettinger | 2009年03月19日 18:12:41 -0500 (2009年3月19日) | 6 lines
 
 * Add implementation notes.
 * Re-order methods so that those touching the underlying data
 structure come first and the derived methods come last.
 ........
 r70477 | raymond.hettinger | 2009年03月19日 18:22:25 -0500 (2009年3月19日) | 1 line
 
 Fix typo
 ........
 r70479 | mark.dickinson | 2009年03月20日 10:51:55 -0500 (2009年3月20日) | 3 lines
 
 Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
 Backport of r70459.
 ........
 r70485 | raymond.hettinger | 2009年03月20日 13:25:49 -0500 (2009年3月20日) | 1 line
 
 Add MutableSet example.
 ........
 r70531 | benjamin.peterson | 2009年03月22日 17:24:58 -0500 (2009年3月22日) | 1 line
 
 AttributeError can be thrown during recursion errors
 ........
 r70533 | raymond.hettinger | 2009年03月22日 19:08:09 -0500 (2009年3月22日) | 6 lines
 
 Add more comments. Improve variable names.
 Make links clearer by using a Link object
 instead of a list. Use proxy links to avoid
 circular references.
 ........
 r70538 | raymond.hettinger | 2009年03月22日 23:42:18 -0500 (2009年3月22日) | 1 line
 
 Move initialization of root link to __init__.
 ........
 r70544 | raymond.hettinger | 2009年03月23日 13:26:59 -0500 (2009年3月23日) | 1 line
 
 Make imported name private and wrap long-line.
 ........
 r70552 | benjamin.peterson | 2009年03月23日 15:47:59 -0500 (2009年3月23日) | 1 line
 
 fix very old names for exception terms #5543
 ........
 r70553 | benjamin.peterson | 2009年03月23日 16:23:30 -0500 (2009年3月23日) | 1 line
 
 revert r70552; wrong fix
 ........
 r70564 | raymond.hettinger | 2009年03月23日 19:17:11 -0500 (2009年3月23日) | 1 line
 
 Add links to related resources.
 ........
 r70601 | raymond.hettinger | 2009年03月25日 17:41:32 -0500 (2009年3月25日) | 1 line
 
 Separate initialization from clearing.
 ........
 r70651 | guilherme.polo | 2009年03月28日 14:17:16 -0500 (2009年3月28日) | 1 line
 
 Typo fix
 ........
 r70672 | collin.winter | 2009年03月28日 22:44:19 -0500 (2009年3月28日) | 4 lines
 
 Add the ability to control the random seed used by regrtest.py -r.
 
 This adds a --randseed option, and makes regrtest.py -r indicate what random seed it's using so that that value can later be fed back to --randseed. This option is useful for tracking down test order-related issues found by make buildbottest, for example.
 ........
 r70702 | bob.ippolito | 2009年03月29日 17:33:58 -0500 (2009年3月29日) | 1 line
 
 Issue 5381: fix regression in pure python code path, Issue 5584: fix a decoder bug for unicode float literals outside of a container
 ........
 r70711 | r.david.murray | 2009年03月30日 10:14:01 -0500 (2009年3月30日) | 2 lines
 
 Convert import try/except to use test_support.import_module().
 ........
 r70712 | benjamin.peterson | 2009年03月30日 10:15:38 -0500 (2009年3月30日) | 1 line
 
 don't rely on the order dict repr #5605
 ........
 r70713 | ronald.oussoren | 2009年03月30日 10:20:46 -0500 (2009年3月30日) | 2 lines
 
 This patch fixes issue 1254695 (wrong argument type conversion in Carbon.Qt)
 ........
 r70714 | brett.cannon | 2009年03月30日 10:20:53 -0500 (2009年3月30日) | 1 line
 
 Add an entry to developers.txt.
 ........
 r70716 | r.david.murray | 2009年03月30日 10:30:34 -0500 (2009年3月30日) | 2 lines
 
 Revert incorrect change.
 ........
 r70719 | ronald.oussoren | 2009年03月30日 11:01:51 -0500 (2009年3月30日) | 2 lines
 
 Fix for issue 896199 (some Carbon modules aren't present in the documentation)
 ........
 r70723 | kurt.kaiser | 2009年03月30日 11:22:00 -0500 (2009年3月30日) | 1 line
 
 Tk 8.5 Text widget requires 'wordprocessor' tabstyle attr to handle mixed space/tab properly. Issue 5120, patch by Guilherme Polo.
 ........
 r70734 | r.david.murray | 2009年03月30日 14:04:00 -0500 (2009年3月30日) | 7 lines
 
 Add import_function method to test.test_support, and modify a number of
 tests that expect to be skipped if imports fail or functions don't
 exist to use import_function and import_module. The ultimate goal is
 to change regrtest to not skip automatically on ImportError. Checking
 in now to make sure the buldbots don't show any errors on platforms
 I can't direct test on.
 ........
 r70747 | r.david.murray | 2009年03月30日 15:04:06 -0500 (2009年3月30日) | 3 lines
 
 Remove references to test_socket_ssl which was deleted in trunk
 in r64392 and py3k in r59038.
 ........
 r70757 | senthil.kumaran | 2009年03月30日 16:51:50 -0500 (2009年3月30日) | 3 lines
 
 Fix for bugs: Issue4675 and Issue4962.
 ........
 r70764 | martin.v.loewis | 2009年03月30日 17:06:33 -0500 (2009年3月30日) | 2 lines
 
 Add several VM developers.
 ........
 r70765 | georg.brandl | 2009年03月30日 17:09:34 -0500 (2009年3月30日) | 1 line
 
 #5199: make warning about vars() assignment more visible.
 ........
 r70768 | andrew.kuchling | 2009年03月30日 17:29:15 -0500 (2009年3月30日) | 1 line
 
 Typo fixes
 ........
 r70769 | andrew.kuchling | 2009年03月30日 17:29:53 -0500 (2009年3月30日) | 1 line
 
 Remove comment
 ........
 r70770 | andrew.kuchling | 2009年03月30日 17:30:20 -0500 (2009年3月30日) | 1 line
 
 Add several items and placeholders
 ........
 r70771 | andrew.kuchling | 2009年03月30日 17:31:11 -0500 (2009年3月30日) | 1 line
 
 Many edits
 ........
 r70772 | barry.warsaw | 2009年03月30日 17:42:17 -0500 (2009年3月30日) | 5 lines
 
 A fix for issue 1974, inspired by the patch from Andi Albrecht (aalbrecht),
 though with some changes by me. This patch should not be back ported or
 forward ported. It's a bit too risky for 2.6 and 3.x does things fairly
 differently.
 ........
 r70773 | georg.brandl | 2009年03月30日 17:43:00 -0500 (2009年3月30日) | 1 line
 
 #5039: make it clear that the impl. note refers to CPython.
 ........
 r70775 | r.david.murray | 2009年03月30日 18:05:48 -0500 (2009年3月30日) | 4 lines
 
 Change more tests to use import_module for the modules that
 should cause tests to be skipped. Also rename import_function
 to the more descriptive get_attribute and add a docstring.
 ........
 r70776 | andrew.kuchling | 2009年03月30日 18:08:24 -0500 (2009年3月30日) | 1 line
 
 typo fix
 ........
 r70777 | andrew.kuchling | 2009年03月30日 18:09:46 -0500 (2009年3月30日) | 1 line
 
 Add more items
 ........
 r70788 | andrew.kuchling | 2009年03月30日 20:21:01 -0500 (2009年3月30日) | 1 line
 
 Add various items
 ........
 r70789 | georg.brandl | 2009年03月30日 20:25:15 -0500 (2009年3月30日) | 1 line
 
 Fix a wrong struct field assignment (docstring as closure).
 ........
 r70807 | jeremy.hylton | 2009年03月31日 08:31:00 -0500 (2009年3月31日) | 2 lines
 
 Update quicktest to match Python 3 branch
 ........
 r70821 | jeremy.hylton | 2009年03月31日 10:04:15 -0500 (2009年3月31日) | 2 lines
 
 Add check for PyDict_Update() error.
 ........
 r70824 | georg.brandl | 2009年03月31日 10:43:20 -0500 (2009年3月31日) | 1 line
 
 #5519: remove reference to Kodos, which seems dead.
 ........
 r70825 | georg.brandl | 2009年03月31日 10:46:30 -0500 (2009年3月31日) | 1 line
 
 #5566: fix versionadded from PyLong ssize_t functions.
 ........
 r70828 | georg.brandl | 2009年03月31日 10:50:16 -0500 (2009年3月31日) | 1 line
 
 #5581: fget argument of abstractproperty is optional as well.
 ........
 r70830 | georg.brandl | 2009年03月31日 11:11:45 -0500 (2009年3月31日) | 1 line
 
 #5529: backport new docs of import semantics written by Brett to 2.x.
 ........
 r70832 | georg.brandl | 2009年03月31日 11:31:11 -0500 (2009年3月31日) | 1 line
 
 #1386675: specify WindowsError as the exception, because it has a winerror attribute that EnvironmentError doesnt have.
 ........
 r70836 | georg.brandl | 2009年03月31日 11:50:25 -0500 (2009年3月31日) | 1 line
 
 #5417: replace references to undocumented functions by ones to documented functions.
 ........
 r70837 | gregory.p.smith | 2009年03月31日 11:54:10 -0500 (2009年3月31日) | 9 lines
 
 The unittest.TestCase.assertEqual() now displays the differences in lists,
 tuples, dicts and sets on failure.
 
 Many new handy type and comparison specific assert* methods have been added
 that fail with error messages actually useful for debugging. Contributed in
 by Google and completed with help from mfoord and GvR at PyCon 2009 sprints.
 
 Discussion lives in http://bugs.python.org/issue2578.
 ........
 r70838 | georg.brandl | 2009年03月31日 11:54:38 -0500 (2009年3月31日) | 1 line
 
 #992207: document that the parser only accepts \\n newlines.
 ........
 r70842 | georg.brandl | 2009年03月31日 12:13:06 -0500 (2009年3月31日) | 1 line
 
 #970783: document PyObject_Generic[GS]etAttr.
 ........
 r70844 | raymond.hettinger | 2009年03月31日 12:47:06 -0500 (2009年3月31日) | 1 line
 
 Per the language summit, the optional fastpath imports should use from-import-star.
 ........
 r70851 | georg.brandl | 2009年03月31日 13:26:55 -0500 (2009年3月31日) | 1 line
 
 #837577: note cryptic return value of spawn*e on invalid env dicts.
 ........
 r70855 | georg.brandl | 2009年03月31日 13:30:37 -0500 (2009年3月31日) | 1 line
 
 #5245: note that PyRun_SimpleString doesnt return on SystemExit.
 ........
 r70856 | r.david.murray | 2009年03月31日 13:32:17 -0500 (2009年3月31日) | 7 lines
 
 A few more test skips via import_module, and change import_module to 
 return the error message produced by importlib, so that if an import 
 in the package whose import is being wrapped is what failed the skip 
 message will contain the name of that module instead of the name of the 
 wrapped module. Also fixed formatting of some previous comments. 
 ........
 r70857 | georg.brandl | 2009年03月31日 13:33:10 -0500 (2009年3月31日) | 1 line
 
 #5227: note that Py_Main doesnt return on SystemExit.
 ........
 r70858 | georg.brandl | 2009年03月31日 13:38:56 -0500 (2009年3月31日) | 1 line
 
 #5241: document missing U in regex howto.
 ........
 r70864 | gregory.p.smith | 2009年03月31日 14:03:28 -0500 (2009年3月31日) | 10 lines
 
 Rename the actual method definitions to the official assertFoo names.
 
 Adds unittests to make sure the old fail* names continue to work now
 and adds a comment that they are pending deprecation.
 
 Also adds a test to confirm that the plural Equals method variants
 continue to exist even though we're unlikely to deprecate those.
 
 http://bugs.python.org/issue2578
 ........
 r70866 | georg.brandl | 2009年03月31日 14:06:57 -0500 (2009年3月31日) | 1 line
 
 #4882: document named group behavior a bit better.
 ........
 r70867 | georg.brandl | 2009年03月31日 14:10:35 -0500 (2009年3月31日) | 1 line
 
 #1096310: document usage of sys.__std*__ a bit better.
 ........
 r70868 | georg.brandl | 2009年03月31日 14:12:17 -0500 (2009年3月31日) | 1 line
 
 #5190: export make_option in __all__.
 ........
 r70869 | georg.brandl | 2009年03月31日 14:14:42 -0500 (2009年3月31日) | 1 line
 
 Fix-up unwanted change.
 ........
 r70870 | georg.brandl | 2009年03月31日 14:26:24 -0500 (2009年3月31日) | 1 line
 
 #4411: document mro() and __mro__. (I hope I got it right.)
 ........
 r70871 | georg.brandl | 2009年03月31日 14:30:56 -0500 (2009年3月31日) | 1 line
 
 #5618: fix typo.
 ........
 r70872 | r.david.murray | 2009年03月31日 14:31:17 -0500 (2009年3月31日) | 3 lines
 
 Delete out-of-date and little-known README from the test
 directory by consensus of devs at pycon sprint.
 ........
 r70873 | josiah.carlson | 2009年03月31日 14:32:34 -0500 (2009年3月31日) | 2 lines
 
 This resolves issue 1161031. Tests pass.
 ........
 r70874 | r.david.murray | 2009年03月31日 14:33:15 -0500 (2009年3月31日) | 5 lines
 
 Improve test_support.import_module docstring, remove
 deprecated flag from get_attribute since it isn't likely
 to do anything useful.
 ........
 r70876 | r.david.murray | 2009年03月31日 14:49:15 -0500 (2009年3月31日) | 4 lines
 
 Remove the regrtest check that turns any ImportError into a skipped test.
 Hopefully all modules whose imports legitimately result in a skipped
 test have been properly wrapped by the previous commits.
 ........
 r70877 | r.david.murray | 2009年03月31日 14:57:24 -0500 (2009年3月31日) | 2 lines
 
 Add NEWS entry for regrtest change.
 ........
 r70878 | gregory.p.smith | 2009年03月31日 14:59:14 -0500 (2009年3月31日) | 3 lines
 
 Issue an actual PendingDeprecationWarning for the TestCase.fail* methods.
 Document the deprecation.
 ........
 r70883 | georg.brandl | 2009年03月31日 15:41:08 -0500 (2009年3月31日) | 1 line
 
 #1674032: return value of flag from Event.wait(). OKed by Guido.
 ........
 r70885 | tarek.ziade | 2009年03月31日 15:48:31 -0500 (2009年3月31日) | 1 line
 
 using log.warn for sys.stderr
 ........
 r70893 | georg.brandl | 2009年03月31日 15:56:32 -0500 (2009年3月31日) | 1 line
 
 #1530012: move TQS section before raw strings.
 ........
 r70894 | benjamin.peterson | 2009年03月31日 16:06:30 -0500 (2009年3月31日) | 1 line
 
 take the usual lock precautions around _active_limbo_lock
 ........
 r70896 | georg.brandl | 2009年03月31日 16:15:33 -0500 (2009年3月31日) | 1 line
 
 #5598: document DocFileSuite *args argument.
 ........
 r70897 | benjamin.peterson | 2009年03月31日 16:34:42 -0500 (2009年3月31日) | 1 line
 
 fix Thread.ident when it is the main thread or a dummy thread #5632
 ........
 r70901 | georg.brandl | 2009年03月31日 16:40:24 -0500 (2009年3月31日) | 2 lines
 
 Remove warning about pending Win9x support removal.
 ........
 r70902 | georg.brandl | 2009年03月31日 16:43:03 -0500 (2009年3月31日) | 1 line
 
 #1675026: add a note about a strange Windows problem, and remove notes about AtheOS.
 ........
 r70903 | georg.brandl | 2009年03月31日 16:45:18 -0500 (2009年3月31日) | 1 line
 
 #1676135: remove trailing slashes from --prefix argument.
 ........
 r70904 | josiah.carlson | 2009年03月31日 16:49:36 -0500 (2009年3月31日) | 3 lines
 
 Made handle_expt_event() be called last, so that we don't accidentally read
 after closing the socket.
 ........
 r70905 | georg.brandl | 2009年03月31日 17:03:40 -0500 (2009年3月31日) | 1 line
 
 #5563: more documentation for bdist_msi.
 ........
 r70906 | georg.brandl | 2009年03月31日 17:11:53 -0500 (2009年3月31日) | 1 line
 
 #1651995: fix _convert_ref for non-ASCII characters.
 ........
 r70907 | georg.brandl | 2009年03月31日 17:18:19 -0500 (2009年3月31日) | 1 line
 
 #3427: document correct return type for urlopen().info().
 ........
 r70908 | jesse.noller | 2009年03月31日 17:20:35 -0500 (2009年3月31日) | 1 line
 
 Issue 5619: Pass MS CRT debug flags into subprocesses
 ........
 r70912 | georg.brandl | 2009年03月31日 17:35:46 -0500 (2009年3月31日) | 1 line
 
 #5617: add a handy function to print a unicode string to gdbinit.
 ........
 r70915 | georg.brandl | 2009年03月31日 17:40:16 -0500 (2009年3月31日) | 1 line
 
 #5018: remove confusing paragraph.
 ........
 r70918 | raymond.hettinger | 2009年03月31日 17:43:03 -0500 (2009年3月31日) | 1 line
 
 Improve examples for collections.deque()
 ........
 r70927 | georg.brandl | 2009年03月31日 18:01:27 -0500 (2009年3月31日) | 1 line
 
 Dont shout to users.
 ........
 r70933 | georg.brandl | 2009年03月31日 19:04:33 -0500 (2009年3月31日) | 2 lines
 
 Issue #5635: Fix running test_sys with tracing enabled.
 ........
 r70934 | josiah.carlson | 2009年03月31日 20:28:11 -0500 (2009年3月31日) | 2 lines
 
 Fix for failing asyncore tests.
 ........
 r70939 | jesse.noller | 2009年03月31日 22:45:50 -0500 (2009年3月31日) | 1 line
 
 Fix multiprocessing.event to match the new threading.Event API
 ........
 r70940 | georg.brandl | 2009年03月31日 23:21:14 -0500 (2009年3月31日) | 2 lines
 
 The SimpleXMLRPCServer's CGI handler now runs like a pony.
 ........
 r70944 | georg.brandl | 2009年03月31日 23:32:39 -0500 (2009年3月31日) | 1 line
 
 #5631: add upload to list of possible commands, which is presented in --help-commands.
 ........
 r70951 | georg.brandl | 2009年04月01日 09:02:27 -0500 (2009年4月01日) | 1 line
 
 Add Maksim, who worked on several issues at the sprint.
 ........
 r70958 | kristjan.jonsson | 2009年04月01日 11:08:34 -0500 (2009年4月01日) | 3 lines
 
 http://bugs.python.org/issue5623
 Dynamically discoverd the size of the ioinfo struct used by the crt for its file descriptors. This should work across all flavors of the CRT. Thanks to Amaury Forgeot d'Arc
 Needs porting to 3.1
 ........
 r70960 | jesse.noller | 2009年04月01日 11:42:19 -0500 (2009年4月01日) | 1 line
 
 Issue 3270: document Listener address restrictions on windows
 ........
 r70962 | brett.cannon | 2009年04月01日 12:07:16 -0500 (2009年4月01日) | 2 lines
 
 Ron DuPlain was given commit privileges at PyCon 2009 to work on 3to2.
 ........
 r70963 | georg.brandl | 2009年04月01日 12:46:01 -0500 (2009年4月01日) | 1 line
 
 #5655: fix docstring oversight.
 ........
 r70964 | brett.cannon | 2009年04月01日 12:52:13 -0500 (2009年4月01日) | 2 lines
 
 Paul Kippes was given commit privileges to work on 3to2.
 ........
 r70968 | michael.foord | 2009年04月01日 13:25:38 -0500 (2009年4月01日) | 1 line
 
 Adding Wing project file
 ........
 r70969 | raymond.hettinger | 2009年04月01日 13:50:56 -0500 (2009年4月01日) | 1 line
 
 Issue #5647: MutableSet.__iand__() no longer mutates self during iteration.
 ........
 r70980 | jack.diederich | 2009年04月01日 15:26:13 -0500 (2009年4月01日) | 3 lines
 
 bounds check arguments to mmap.move(). All of them. Really.
 fixes crasher on OS X 10.5
 ........
 r70981 | senthil.kumaran | 2009年04月01日 15:26:33 -0500 (2009年4月01日) | 3 lines
 
 Fix for issue5040. Adding test for Content-Length
 ........
 r70986 | raymond.hettinger | 2009年04月01日 15:50:58 -0500 (2009年4月01日) | 1 line
 
 Add link to an alternative generator with a long-period.
 ........
 r70993 | georg.brandl | 2009年04月01日 16:05:44 -0500 (2009年4月01日) | 1 line
 
 Add NEWS item.
 ........
 r70994 | georg.brandl | 2009年04月01日 16:06:30 -0500 (2009年4月01日) | 1 line
 
 Revert accidental checkin.
 ........
 r70998 | georg.brandl | 2009年04月01日 16:54:21 -0500 (2009年4月01日) | 1 line
 
 In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
 ........
 r71001 | brett.cannon | 2009年04月01日 18:01:12 -0500 (2009年4月01日) | 3 lines
 
 Add my initials to Misc/developers.txt. Names are now sorted by number of
 characters in the person's name.
 ........
 r71004 | benjamin.peterson | 2009年04月01日 18:15:49 -0500 (2009年4月01日) | 1 line
 
 remove double underscores
 ........
 r71006 | georg.brandl | 2009年04月01日 18:32:17 -0500 (2009年4月01日) | 1 line
 
 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
 ........
 r71008 | andrew.kuchling | 2009年04月01日 19:02:14 -0500 (2009年4月01日) | 1 line
 
 Typo fix
 ........
 r71009 | jesse.noller | 2009年04月01日 19:03:28 -0500 (2009年4月01日) | 1 line
 
 issue5545: Switch to Autoconf for multiprocessing; special thanks to Martin Lowis for help
 ........
 r71010 | benjamin.peterson | 2009年04月01日 19:11:52 -0500 (2009年4月01日) | 1 line
 
 fix markup
 ........
 r71011 | benjamin.peterson | 2009年04月01日 19:12:47 -0500 (2009年4月01日) | 1 line
 
 this should be :noindex:
 ........
 r71019 | georg.brandl | 2009年04月01日 21:00:01 -0500 (2009年4月01日) | 1 line
 
 Fix test_doctest, missed two assignments to curframe.
 ........
 r71022 | jesse.noller | 2009年04月01日 21:32:55 -0500 (2009年4月01日) | 1 line
 
 Issue 3110: Additional protection for SEM_VALUE_MAX on platforms, thanks to Martin Loewis
 ........
 r71023 | kurt.kaiser | 2009年04月01日 21:44:54 -0500 (2009年4月01日) | 3 lines
 
 Remove port spec from run.py and fix bug where
 subprocess fails to extract port from command line
 when warnings are present.
 ........
 r71024 | georg.brandl | 2009年04月01日 21:47:44 -0500 (2009年4月01日) | 4 lines
 
 In PyErr_GivenExceptionMatches, temporarily bump the recursion
 limit, so that in the most common case PyObject_IsSubclass will
 not raise a recursion error we have to ignore anyway.
 ........
 r71026 | benjamin.peterson | 2009年04月01日 21:52:46 -0500 (2009年4月01日) | 1 line
 
 fix error handling
 ........
 r71029 | senthil.kumaran | 2009年04月01日 22:00:34 -0500 (2009年4月01日) | 3 lines
 
 Fixing the issue4860. Escaping embedded '"' character in js_output() method of Morsel.
 ........
 r71031 | brett.cannon | 2009年04月01日 22:17:39 -0500 (2009年4月01日) | 6 lines
 
 PyImport_AppendInittab() took a char * as a first argument even though that
 string was stored beyond the life of the call. Changed the signature to be
 const char * to help make this point.
 
 Closes issue #1419652.
 ........
 r71032 | michael.foord | 2009年04月01日 22:20:38 -0500 (2009年4月01日) | 13 lines
 
 Better exception messages for unittest assert methods.
 
 - unittest.assertNotEqual() now uses the inequality operator (!=) instead 
 of the equality operator.
 
 - Default assertTrue and assertFalse messages are now useful. 
 
 - TestCase has a longMessage attribute. This defaults to False, but if set to True 
 useful error messages are shown in addition to explicit messages passed to assert methods.
 
 Issue #5663
 ........
 r71033 | brett.cannon | 2009年04月01日 22:34:53 -0500 (2009年4月01日) | 3 lines
 
 Fix two issues introduced by issue #71031 by changing the signature of
 PyImport_AppendInittab() to take a const char *.
 ........
 r71036 | jesse.noller | 2009年04月01日 23:22:09 -0500 (2009年4月01日) | 1 line
 
 Issue 3551: Raise ValueError if the size causes ERROR_NO_SYSTEM_RESOURCES
 ........
 r71037 | r.david.murray | 2009年04月01日 23:34:04 -0500 (2009年4月01日) | 6 lines
 
 Clarify that datetime strftime does not produce leap seconds and datetime
 strptime does not accept it in the strftime behavior section of the
 datetime docs.
 
 Closes issue 2568.
 ........
 r71041 | jesse.noller | 2009年04月02日 00:17:26 -0500 (2009年4月02日) | 1 line
 
 Add custom initializer argument to multiprocess.Manager*, courtesy of lekma
 ........
 r71043 | michael.foord | 2009年04月02日 00:51:54 -0500 (2009年4月02日) | 7 lines
 
 Store the functions in the _type_equality_funcs as wrapped objects that are deep copyable.
 
 This allows for the deep copying of TestCase instances.
 
 Issue 5660
 ........
 r71056 | georg.brandl | 2009年04月02日 12:43:07 -0500 (2009年4月02日) | 2 lines
 
 Actually the displayhook should print the repr.
 ........
 r71058 | georg.brandl | 2009年04月02日 13:09:04 -0500 (2009年4月02日) | 3 lines
 
 PyErr_NormalizeException may not set an error, so convert the PyErr_SetObject
 call on hitting the recursion limit into just assigning it to the arguments provided.
 ........
 r71059 | mark.dickinson | 2009年04月02日 13:39:37 -0500 (2009年4月02日) | 2 lines
 
 sys.long_info attributes should be ints, not longs
 ........
 r71070 | antoine.pitrou | 2009年04月02日 16:18:34 -0500 (2009年4月02日) | 3 lines
 
 Issue #2396: backport the memoryview object.
 ........
 r71073 | raymond.hettinger | 2009年04月02日 17:25:40 -0500 (2009年4月02日) | 4 lines
 
 Have namedtuple's field renamer assign names that
 are consistent with the corresponding tuple index.
 ........
 r71075 | raymond.hettinger | 2009年04月02日 17:34:17 -0500 (2009年4月02日) | 1 line
 
 Update docs for namedtuple's renaming change.
 ........
 r71078 | raymond.hettinger | 2009年04月02日 21:43:54 -0500 (2009年4月02日) | 4 lines
 
 Localize the function lookup in timeit.
 ........
................
 r71122 | raymond.hettinger | 2009年04月04日 01:39:52 -0400 (2009年4月04日) | 1 line
 
 Add helpful link.
................
 r71125 | r.david.murray | 2009年04月04日 02:46:11 -0400 (2009年4月04日) | 8 lines
 
 Blocked revisions 71123 via svnmerge
 
 ........
 r71123 | r.david.murray | 2009年04月04日 02:39:56 -0400 (2009年4月04日) | 2 lines
 
 Fix error in description of 'oct' (issue 5678).
 ........
................
 r71128 | raymond.hettinger | 2009年04月04日 04:48:03 -0400 (2009年4月04日) | 1 line
 
 Replace the localized min/max calls with normal if/else
................
 r71137 | raymond.hettinger | 2009年04月04日 06:47:35 -0400 (2009年4月04日) | 1 line
 
 Start building-up the whatsnew document for Py3.1
................
 r71138 | raymond.hettinger | 2009年04月04日 07:08:48 -0400 (2009年4月04日) | 1 line
 
 More updates to whatsnew
................
 r71139 | raymond.hettinger | 2009年04月04日 07:59:00 -0400 (2009年4月04日) | 1 line
 
 More notes on 3.1 improvements.
................
 r71140 | benjamin.peterson | 2009年04月04日 08:33:52 -0400 (2009年4月04日) | 1 line
 
 revert r71118 because it blocked an excess of revisions
................
 r71141 | raymond.hettinger | 2009年04月04日 08:35:58 -0400 (2009年4月04日) | 1 line
 
 Complete the first-pass at whatsnew.
................
 r71142 | benjamin.peterson | 2009年04月04日 08:40:17 -0400 (2009年4月04日) | 94 lines
 
 Blocked revisions 70711,70713,70716,70719,70747,70772,70821,70830,70844,70873,70901-70902,70904,70918,70934,70969,70986,71026,71073,71075,71078 via svnmerge
 
 ........
 r70711 | r.david.murray | 2009年03月30日 10:14:01 -0500 (2009年3月30日) | 2 lines
 
 Convert import try/except to use test_support.import_module().
 ........
 r70713 | ronald.oussoren | 2009年03月30日 10:20:46 -0500 (2009年3月30日) | 2 lines
 
 This patch fixes issue 1254695 (wrong argument type conversion in Carbon.Qt)
 ........
 r70716 | r.david.murray | 2009年03月30日 10:30:34 -0500 (2009年3月30日) | 2 lines
 
 Revert incorrect change.
 ........
 r70719 | ronald.oussoren | 2009年03月30日 11:01:51 -0500 (2009年3月30日) | 2 lines
 
 Fix for issue 896199 (some Carbon modules aren't present in the documentation)
 ........
 r70747 | r.david.murray | 2009年03月30日 15:04:06 -0500 (2009年3月30日) | 3 lines
 
 Remove references to test_socket_ssl which was deleted in trunk
 in r64392 and py3k in r59038.
 ........
 r70772 | barry.warsaw | 2009年03月30日 17:42:17 -0500 (2009年3月30日) | 5 lines
 
 A fix for issue 1974, inspired by the patch from Andi Albrecht (aalbrecht),
 though with some changes by me. This patch should not be back ported or
 forward ported. It's a bit too risky for 2.6 and 3.x does things fairly
 differently.
 ........
 r70821 | jeremy.hylton | 2009年03月31日 10:04:15 -0500 (2009年3月31日) | 2 lines
 
 Add check for PyDict_Update() error.
 ........
 r70830 | georg.brandl | 2009年03月31日 11:11:45 -0500 (2009年3月31日) | 1 line
 
 #5529: backport new docs of import semantics written by Brett to 2.x.
 ........
 r70844 | raymond.hettinger | 2009年03月31日 12:47:06 -0500 (2009年3月31日) | 1 line
 
 Per the language summit, the optional fastpath imports should use from-import-star.
 ........
 r70873 | josiah.carlson | 2009年03月31日 14:32:34 -0500 (2009年3月31日) | 2 lines
 
 This resolves issue 1161031. Tests pass.
 ........
 r70901 | georg.brandl | 2009年03月31日 16:40:24 -0500 (2009年3月31日) | 2 lines
 
 Remove warning about pending Win9x support removal.
 ........
 r70902 | georg.brandl | 2009年03月31日 16:43:03 -0500 (2009年3月31日) | 1 line
 
 #1675026: add a note about a strange Windows problem, and remove notes about AtheOS.
 ........
 r70904 | josiah.carlson | 2009年03月31日 16:49:36 -0500 (2009年3月31日) | 3 lines
 
 Made handle_expt_event() be called last, so that we don't accidentally read
 after closing the socket.
 ........
 r70918 | raymond.hettinger | 2009年03月31日 17:43:03 -0500 (2009年3月31日) | 1 line
 
 Improve examples for collections.deque()
 ........
 r70934 | josiah.carlson | 2009年03月31日 20:28:11 -0500 (2009年3月31日) | 2 lines
 
 Fix for failing asyncore tests.
 ........
 r70969 | raymond.hettinger | 2009年04月01日 13:50:56 -0500 (2009年4月01日) | 1 line
 
 Issue #5647: MutableSet.__iand__() no longer mutates self during iteration.
 ........
 r70986 | raymond.hettinger | 2009年04月01日 15:50:58 -0500 (2009年4月01日) | 1 line
 
 Add link to an alternative generator with a long-period.
 ........
 r71026 | benjamin.peterson | 2009年04月01日 21:52:46 -0500 (2009年4月01日) | 1 line
 
 fix error handling
 ........
 r71073 | raymond.hettinger | 2009年04月02日 17:25:40 -0500 (2009年4月02日) | 4 lines
 
 Have namedtuple's field renamer assign names that
 are consistent with the corresponding tuple index.
 ........
 r71075 | raymond.hettinger | 2009年04月02日 17:34:17 -0500 (2009年4月02日) | 1 line
 
 Update docs for namedtuple's renaming change.
 ........
 r71078 | raymond.hettinger | 2009年04月02日 21:43:54 -0500 (2009年4月02日) | 4 lines
 
 Localize the function lookup in timeit.
 ........
................
 r71143 | benjamin.peterson | 2009年04月04日 08:42:53 -0400 (2009年4月04日) | 1 line
 
 typo
................
 r71144 | raymond.hettinger | 2009年04月04日 08:46:57 -0400 (2009年4月04日) | 1 line
 
 Eliminate a duplicate entry.
................
 r71146 | raymond.hettinger | 2009年04月04日 09:01:19 -0400 (2009年4月04日) | 1 line
 
 Fix nits.
................
 r71147 | raymond.hettinger | 2009年04月04日 09:13:56 -0400 (2009年4月04日) | 1 line
 
 Remove minor entry. Add the ttk module.
................
 r71148 | raymond.hettinger | 2009年04月04日 09:20:55 -0400 (2009年4月04日) | 1 line
 
 Note an improvement to pydoc.
................
 r71151 | antoine.pitrou | 2009年04月04日 10:09:30 -0400 (2009年4月04日) | 3 lines
 
 Fix test_memoryio under Windows
................
 r71154 | matthias.klose | 2009年04月04日 10:32:42 -0400 (2009年4月04日) | 10 lines
 
 Merged revisions 71152 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r71152 | matthias.klose | 2009年04月04日 16:18:13 +0200 (Sa, 04 Apr 2009) | 3 lines
 
 - Issue #3845: In PyRun_SimpleFileExFlags avoid invalid memory access with
 short file names.
 ........
................
 r71156 | benjamin.peterson | 2009年04月04日 11:32:08 -0400 (2009年4月04日) | 1 line
 
 try to fix svnmerge-blocked property
................
 r71157 | benjamin.peterson | 2009年04月04日 11:38:19 -0400 (2009年4月04日) | 90 lines
 
 Blocked revisions 70711,70713,70716,70719,70747,70772,70821,70830,70844,70873,70901-70902,70904,70918,70934,70969,71026,71073,71075,71078 via svnmerge
 
 ........
 r70711 | r.david.murray | 2009年03月30日 10:14:01 -0500 (2009年3月30日) | 2 lines
 
 Convert import try/except to use test_support.import_module().
 ........
 r70713 | ronald.oussoren | 2009年03月30日 10:20:46 -0500 (2009年3月30日) | 2 lines
 
 This patch fixes issue 1254695 (wrong argument type conversion in Carbon.Qt)
 ........
 r70716 | r.david.murray | 2009年03月30日 10:30:34 -0500 (2009年3月30日) | 2 lines
 
 Revert incorrect change.
 ........
 r70719 | ronald.oussoren | 2009年03月30日 11:01:51 -0500 (2009年3月30日) | 2 lines
 
 Fix for issue 896199 (some Carbon modules aren't present in the documentation)
 ........
 r70747 | r.david.murray | 2009年03月30日 15:04:06 -0500 (2009年3月30日) | 3 lines
 
 Remove references to test_socket_ssl which was deleted in trunk
 in r64392 and py3k in r59038.
 ........
 r70772 | barry.warsaw | 2009年03月30日 17:42:17 -0500 (2009年3月30日) | 5 lines
 
 A fix for issue 1974, inspired by the patch from Andi Albrecht (aalbrecht),
 though with some changes by me. This patch should not be back ported or
 forward ported. It's a bit too risky for 2.6 and 3.x does things fairly
 differently.
 ........
 r70821 | jeremy.hylton | 2009年03月31日 10:04:15 -0500 (2009年3月31日) | 2 lines
 
 Add check for PyDict_Update() error.
 ........
 r70830 | georg.brandl | 2009年03月31日 11:11:45 -0500 (2009年3月31日) | 1 line
 
 #5529: backport new docs of import semantics written by Brett to 2.x.
 ........
 r70844 | raymond.hettinger | 2009年03月31日 12:47:06 -0500 (2009年3月31日) | 1 line
 
 Per the language summit, the optional fastpath imports should use from-import-star.
 ........
 r70873 | josiah.carlson | 2009年03月31日 14:32:34 -0500 (2009年3月31日) | 2 lines
 
 This resolves issue 1161031. Tests pass.
 ........
 r70901 | georg.brandl | 2009年03月31日 16:40:24 -0500 (2009年3月31日) | 2 lines
 
 Remove warning about pending Win9x support removal.
 ........
 r70902 | georg.brandl | 2009年03月31日 16:43:03 -0500 (2009年3月31日) | 1 line
 
 #1675026: add a note about a strange Windows problem, and remove notes about AtheOS.
 ........
 r70904 | josiah.carlson | 2009年03月31日 16:49:36 -0500 (2009年3月31日) | 3 lines
 
 Made handle_expt_event() be called last, so that we don't accidentally read
 after closing the socket.
 ........
 r70918 | raymond.hettinger | 2009年03月31日 17:43:03 -0500 (2009年3月31日) | 1 line
 
 Improve examples for collections.deque()
 ........
 r70934 | josiah.carlson | 2009年03月31日 20:28:11 -0500 (2009年3月31日) | 2 lines
 
 Fix for failing asyncore tests.
 ........
 r70969 | raymond.hettinger | 2009年04月01日 13:50:56 -0500 (2009年4月01日) | 1 line
 
 Issue #5647: MutableSet.__iand__() no longer mutates self during iteration.
 ........
 r71026 | benjamin.peterson | 2009年04月01日 21:52:46 -0500 (2009年4月01日) | 1 line
 
 fix error handling
 ........
 r71073 | raymond.hettinger | 2009年04月02日 17:25:40 -0500 (2009年4月02日) | 4 lines
 
 Have namedtuple's field renamer assign names that
 are consistent with the corresponding tuple index.
 ........
 r71075 | raymond.hettinger | 2009年04月02日 17:34:17 -0500 (2009年4月02日) | 1 line
 
 Update docs for namedtuple's renaming change.
 ........
 r71078 | raymond.hettinger | 2009年04月02日 21:43:54 -0500 (2009年4月02日) | 4 lines
 
 Localize the function lookup in timeit.
 ........
................
 r71162 | matthias.klose | 2009年04月04日 11:54:25 -0400 (2009年4月04日) | 9 lines
 
 Merged revisions 71159 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r71159 | matthias.klose | 2009年04月04日 17:51:23 +0200 (Sa, 04 Apr 2009) | 2 lines
 
 - Py_DECREF: Add `do { ... } while (0)' to avoid compiler warnings.
 ........
................
 r71169 | benjamin.peterson | 2009年04月04日 12:35:46 -0400 (2009年4月04日) | 59 lines
 
 Merged revisions 70837,70864,70878,71004,71032,71043 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70837 | gregory.p.smith | 2009年03月31日 11:54:10 -0500 (2009年3月31日) | 9 lines
 
 The unittest.TestCase.assertEqual() now displays the differences in lists,
 tuples, dicts and sets on failure.
 
 Many new handy type and comparison specific assert* methods have been added
 that fail with error messages actually useful for debugging. Contributed in
 by Google and completed with help from mfoord and GvR at PyCon 2009 sprints.
 
 Discussion lives in http://bugs.python.org/issue2578.
 ........
 r70864 | gregory.p.smith | 2009年03月31日 14:03:28 -0500 (2009年3月31日) | 10 lines
 
 Rename the actual method definitions to the official assertFoo names.
 
 Adds unittests to make sure the old fail* names continue to work now
 and adds a comment that they are pending deprecation.
 
 Also adds a test to confirm that the plural Equals method variants
 continue to exist even though we're unlikely to deprecate those.
 
 http://bugs.python.org/issue2578
 ........
 r70878 | gregory.p.smith | 2009年03月31日 14:59:14 -0500 (2009年3月31日) | 3 lines
 
 Issue an actual PendingDeprecationWarning for the TestCase.fail* methods.
 Document the deprecation.
 ........
 r71004 | benjamin.peterson | 2009年04月01日 18:15:49 -0500 (2009年4月01日) | 1 line
 
 remove double underscores
 ........
 r71032 | michael.foord | 2009年04月01日 22:20:38 -0500 (2009年4月01日) | 13 lines
 
 Better exception messages for unittest assert methods.
 
 - unittest.assertNotEqual() now uses the inequality operator (!=) instead 
 of the equality operator.
 
 - Default assertTrue and assertFalse messages are now useful. 
 
 - TestCase has a longMessage attribute. This defaults to False, but if set to True 
 useful error messages are shown in addition to explicit messages passed to assert methods.
 
 Issue #5663
 ........
 r71043 | michael.foord | 2009年04月02日 00:51:54 -0500 (2009年4月02日) | 7 lines
 
 Store the functions in the _type_equality_funcs as wrapped objects that are deep copyable.
 
 This allows for the deep copying of TestCase instances.
 
 Issue 5660
 ........
................
 r71170 | benjamin.peterson | 2009年04月04日 12:38:09 -0400 (2009年4月04日) | 9 lines
 
 Merged revisions 71163 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r71163 | benjamin.peterson | 2009年04月04日 11:05:51 -0500 (2009年4月04日) | 1 line
 
 revert r71159 since it broke the build
 ........
................
 r71171 | benjamin.peterson | 2009年04月04日 12:39:09 -0400 (2009年4月04日) | 1 line
 
 fix test_unittest
................
 r71172 | benjamin.peterson | 2009年04月04日 12:46:24 -0400 (2009年4月04日) | 1 line
 
 mark dictionary assertElementsSame test as an expected failure
................
 r71173 | benjamin.peterson | 2009年04月04日 12:47:31 -0400 (2009年4月04日) | 1 line
 
 fix name
................
 r71174 | benjamin.peterson | 2009年04月04日 13:09:35 -0400 (2009年4月04日) | 1 line
 
 #5391 make mmap work exclusively with bytes
................
 r71176 | benjamin.peterson | 2009年04月04日 13:26:32 -0400 (2009年4月04日) | 1 line
 
 must provide this method
................
 r71177 | hirokazu.yamamoto | 2009年04月04日 13:35:38 -0400 (2009年4月04日) | 8 lines
 
 Blocked revisions 71175 via svnmerge
 
 ........
 r71175 | hirokazu.yamamoto | 2009年04月05日 02:20:05 +0900 | 1 line
 
 No behavior change.
 ........
................
 r71178 | antoine.pitrou | 2009年04月04日 13:36:05 -0400 (2009年4月04日) | 3 lines
 
 Skip test_recursionlimit_fatalerror under Windows because it generates an annoying and misleading crash dialog.
................
 r71180 | martin.v.loewis | 2009年04月04日 14:48:39 -0400 (2009年4月04日) | 9 lines
 
 Merged revisions 71179 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r71179 | martin.v.loewis | 2009年04月04日 20:44:44 +0200 (Sa, 04 Apr 2009) | 2 lines
 
 Issue #5470: Package zipdir.zip.
 ........
................
 r71183 | michael.foord | 2009年04月04日 14:55:09 -0400 (2009年4月04日) | 9 lines
 
 Patch for Py3k with fallback for comparing unsortable sequences in
 assertSameElements.
 
 Removed the expected failure and added another test case to confirm that
 this patch works for unsortable sequences that are the same (no fail)
 and different (fail).
 
 Issue #2578
................
 r71184 | eric.smith | 2009年04月04日 15:35:49 -0400 (2009年4月04日) | 1 line
 
 Resolves issue 5690: accidentally skipping code in non-debug build.
................
 r71185 | alexandre.vassalotti | 2009年04月04日 15:58:40 -0400 (2009年4月04日) | 4 lines
 
 Issue 5682: Move _io module into its own subdirectory.
 
 Reviewed by: Antoine Pitrou
................
 r71186 | kurt.kaiser | 2009年04月04日 16:13:23 -0400 (2009年4月04日) | 11 lines
 
 Merged revisions 71023 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r71023 | kurt.kaiser | 2009年04月01日 22:44:54 -0400 (2009年4月01日) | 3 lines
 
 Remove port spec from run.py and fix bug where
 subprocess fails to extract port from command line
 when warnings are present.
 ........
................
 r71187 | kurt.kaiser | 2009年04月04日 16:20:29 -0400 (2009年4月04日) | 1 line
 
 Convert print to Py3
................
 r71188 | kurt.kaiser | 2009年04月04日 16:34:16 -0400 (2009年4月04日) | 11 lines
 
 Merged revisions 71023 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r71023 | kurt.kaiser | 2009年04月01日 22:44:54 -0400 (2009年4月01日) | 3 lines
 
 Remove port spec from run.py and fix bug where
 subprocess fails to extract port from command line
 when warnings are present.
 ........
................
 r71189 | kurt.kaiser | 2009年04月04日 16:38:52 -0400 (2009年4月04日) | 9 lines
 
 Merged revisions 70723 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r70723 | kurt.kaiser | 2009年03月30日 12:22:00 -0400 (2009年3月30日) | 1 line
 
 Tk 8.5 Text widget requires 'wordprocessor' tabstyle attr to handle mixed space/tab properly. Issue 5120, patch by Guilherme Polo.
 ........
................
 r71192 | benjamin.peterson | 2009年04月04日 17:06:52 -0400 (2009年4月04日) | 1 line
 
 bump version to 3.1a2
................
 r71193 | kurt.kaiser | 2009年04月04日 17:07:39 -0400 (2009年4月04日) | 12 lines
 
 Merged revisions 71126 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r71126 | kurt.kaiser | 2009年04月04日 03:03:48 -0400 (2009年4月04日) | 5 lines
 
 Allow multiple IDLE GUI/subprocess pairs to exist
 simultaneously. Thanks to David Scherer for suggesting
 the use of an ephemeral port for the GUI.
 Patch 1529142 Weeble.
 ........
................
 r71194 | benjamin.peterson | 2009年04月04日 17:08:03 -0400 (2009年4月04日) | 1 line
 
 I don't think RELNOTES is useful anymore
................
Added:
 python/branches/py3k-short-float-repr/Demo/distutils/test2to3/test/
 - copied from r71194, /python/branches/py3k/Demo/distutils/test2to3/test/
 python/branches/py3k-short-float-repr/Lib/distutils/tests/test_clean.py
 - copied unchanged from r71194, /python/branches/py3k/Lib/distutils/tests/test_clean.py
 python/branches/py3k-short-float-repr/Lib/distutils/tests/test_install_data.py
 - copied unchanged from r71194, /python/branches/py3k/Lib/distutils/tests/test_install_data.py
 python/branches/py3k-short-float-repr/Lib/distutils/tests/test_install_headers.py
 - copied unchanged from r71194, /python/branches/py3k/Lib/distutils/tests/test_install_headers.py
 python/branches/py3k-short-float-repr/Lib/test/test_flufl.py
 - copied unchanged from r71194, /python/branches/py3k/Lib/test/test_flufl.py
 python/branches/py3k-short-float-repr/Modules/_io/
 - copied from r71194, /python/branches/py3k/Modules/_io/
Removed:
 python/branches/py3k-short-float-repr/Lib/email/test/test_email_codecs_renamed.py
 python/branches/py3k-short-float-repr/Modules/_bufferedio.c
 python/branches/py3k-short-float-repr/Modules/_bytesio.c
 python/branches/py3k-short-float-repr/Modules/_fileio.c
 python/branches/py3k-short-float-repr/Modules/_iobase.c
 python/branches/py3k-short-float-repr/Modules/_iomodule.h
 python/branches/py3k-short-float-repr/Modules/_stringio.c
 python/branches/py3k-short-float-repr/Modules/_textio.c
 python/branches/py3k-short-float-repr/Modules/io.c
 python/branches/py3k-short-float-repr/RELNOTES
Modified:
 python/branches/py3k-short-float-repr/ (props changed)
 python/branches/py3k-short-float-repr/Demo/distutils/test2to3/ (props changed)
 python/branches/py3k-short-float-repr/Demo/distutils/test2to3/setup.py
 python/branches/py3k-short-float-repr/Doc/c-api/arg.rst
 python/branches/py3k-short-float-repr/Doc/c-api/exceptions.rst
 python/branches/py3k-short-float-repr/Doc/c-api/import.rst
 python/branches/py3k-short-float-repr/Doc/c-api/long.rst
 python/branches/py3k-short-float-repr/Doc/distutils/setupscript.rst
 python/branches/py3k-short-float-repr/Doc/extending/extending.rst
 python/branches/py3k-short-float-repr/Doc/extending/newtypes.rst
 python/branches/py3k-short-float-repr/Doc/howto/regex.rst
 python/branches/py3k-short-float-repr/Doc/library/abc.rst
 python/branches/py3k-short-float-repr/Doc/library/aifc.rst
 python/branches/py3k-short-float-repr/Doc/library/asynchat.rst
 python/branches/py3k-short-float-repr/Doc/library/atexit.rst
 python/branches/py3k-short-float-repr/Doc/library/base64.rst
 python/branches/py3k-short-float-repr/Doc/library/bdb.rst
 python/branches/py3k-short-float-repr/Doc/library/binascii.rst
 python/branches/py3k-short-float-repr/Doc/library/collections.rst
 python/branches/py3k-short-float-repr/Doc/library/csv.rst
 python/branches/py3k-short-float-repr/Doc/library/datetime.rst
 python/branches/py3k-short-float-repr/Doc/library/email.header.rst
 python/branches/py3k-short-float-repr/Doc/library/functions.rst
 python/branches/py3k-short-float-repr/Doc/library/http.client.rst
 python/branches/py3k-short-float-repr/Doc/library/importlib.rst
 python/branches/py3k-short-float-repr/Doc/library/io.rst
 python/branches/py3k-short-float-repr/Doc/library/mmap.rst
 python/branches/py3k-short-float-repr/Doc/library/os.path.rst
 python/branches/py3k-short-float-repr/Doc/library/pickle.rst
 python/branches/py3k-short-float-repr/Doc/library/pickletools.rst
 python/branches/py3k-short-float-repr/Doc/library/random.rst
 python/branches/py3k-short-float-repr/Doc/library/shelve.rst
 python/branches/py3k-short-float-repr/Doc/library/time.rst
 python/branches/py3k-short-float-repr/Doc/library/unittest.rst
 python/branches/py3k-short-float-repr/Doc/library/urllib.error.rst
 python/branches/py3k-short-float-repr/Doc/library/urllib.request.rst
 python/branches/py3k-short-float-repr/Doc/license.rst
 python/branches/py3k-short-float-repr/Doc/reference/datamodel.rst
 python/branches/py3k-short-float-repr/Doc/whatsnew/3.1.rst
 python/branches/py3k-short-float-repr/Grammar/Grammar
 python/branches/py3k-short-float-repr/Include/bytesobject.h
 python/branches/py3k-short-float-repr/Include/code.h
 python/branches/py3k-short-float-repr/Include/compile.h
 python/branches/py3k-short-float-repr/Include/import.h
 python/branches/py3k-short-float-repr/Include/parsetok.h
 python/branches/py3k-short-float-repr/Include/patchlevel.h
 python/branches/py3k-short-float-repr/Include/pythonrun.h
 python/branches/py3k-short-float-repr/Include/unicodeobject.h
 python/branches/py3k-short-float-repr/Lib/__future__.py
 python/branches/py3k-short-float-repr/Lib/_abcoll.py
 python/branches/py3k-short-float-repr/Lib/_pyio.py
 python/branches/py3k-short-float-repr/Lib/_strptime.py
 python/branches/py3k-short-float-repr/Lib/bisect.py
 python/branches/py3k-short-float-repr/Lib/cgitb.py
 python/branches/py3k-short-float-repr/Lib/collections.py
 python/branches/py3k-short-float-repr/Lib/distutils/__init__.py
 python/branches/py3k-short-float-repr/Lib/distutils/cmd.py
 python/branches/py3k-short-float-repr/Lib/distutils/command/build_ext.py
 python/branches/py3k-short-float-repr/Lib/distutils/command/install_data.py
 python/branches/py3k-short-float-repr/Lib/distutils/command/install_headers.py
 python/branches/py3k-short-float-repr/Lib/distutils/command/register.py
 python/branches/py3k-short-float-repr/Lib/distutils/command/upload.py
 python/branches/py3k-short-float-repr/Lib/distutils/extension.py
 python/branches/py3k-short-float-repr/Lib/distutils/tests/support.py
 python/branches/py3k-short-float-repr/Lib/distutils/tests/test_build_ext.py
 python/branches/py3k-short-float-repr/Lib/distutils/tests/test_config.py
 python/branches/py3k-short-float-repr/Lib/distutils/tests/test_msvc9compiler.py
 python/branches/py3k-short-float-repr/Lib/distutils/tests/test_register.py
 python/branches/py3k-short-float-repr/Lib/distutils/tests/test_sdist.py
 python/branches/py3k-short-float-repr/Lib/distutils/tests/test_upload.py
 python/branches/py3k-short-float-repr/Lib/distutils/util.py
 python/branches/py3k-short-float-repr/Lib/email/generator.py
 python/branches/py3k-short-float-repr/Lib/email/test/test_email.py
 python/branches/py3k-short-float-repr/Lib/email/test/test_email_codecs.py (contents, props changed)
 python/branches/py3k-short-float-repr/Lib/http/client.py
 python/branches/py3k-short-float-repr/Lib/http/cookies.py
 python/branches/py3k-short-float-repr/Lib/http/server.py
 python/branches/py3k-short-float-repr/Lib/idlelib/EditorWindow.py
 python/branches/py3k-short-float-repr/Lib/idlelib/NEWS.txt
 python/branches/py3k-short-float-repr/Lib/idlelib/PyShell.py
 python/branches/py3k-short-float-repr/Lib/idlelib/idlever.py
 python/branches/py3k-short-float-repr/Lib/idlelib/rpc.py
 python/branches/py3k-short-float-repr/Lib/idlelib/run.py
 python/branches/py3k-short-float-repr/Lib/importlib/_bootstrap.py
 python/branches/py3k-short-float-repr/Lib/importlib/test/import_/test_path.py
 python/branches/py3k-short-float-repr/Lib/importlib/test/source/test_abc_loader.py
 python/branches/py3k-short-float-repr/Lib/importlib/test/util.py
 python/branches/py3k-short-float-repr/Lib/io.py
 python/branches/py3k-short-float-repr/Lib/locale.py
 python/branches/py3k-short-float-repr/Lib/mailbox.py
 python/branches/py3k-short-float-repr/Lib/multiprocessing/queues.py
 python/branches/py3k-short-float-repr/Lib/site.py
 python/branches/py3k-short-float-repr/Lib/symtable.py
 python/branches/py3k-short-float-repr/Lib/test/buffer_tests.py
 python/branches/py3k-short-float-repr/Lib/test/regrtest.py
 python/branches/py3k-short-float-repr/Lib/test/support.py
 python/branches/py3k-short-float-repr/Lib/test/test___all__.py
 python/branches/py3k-short-float-repr/Lib/test/test_asynchat.py
 python/branches/py3k-short-float-repr/Lib/test/test_bz2.py
 python/branches/py3k-short-float-repr/Lib/test/test_collections.py
 python/branches/py3k-short-float-repr/Lib/test/test_crypt.py
 python/branches/py3k-short-float-repr/Lib/test/test_csv.py
 python/branches/py3k-short-float-repr/Lib/test/test_ctypes.py
 python/branches/py3k-short-float-repr/Lib/test/test_curses.py
 python/branches/py3k-short-float-repr/Lib/test/test_dbm.py
 python/branches/py3k-short-float-repr/Lib/test/test_dbm_gnu.py
 python/branches/py3k-short-float-repr/Lib/test/test_dbm_ndbm.py
 python/branches/py3k-short-float-repr/Lib/test/test_exceptions.py
 python/branches/py3k-short-float-repr/Lib/test/test_fcntl.py
 python/branches/py3k-short-float-repr/Lib/test/test_fork1.py
 python/branches/py3k-short-float-repr/Lib/test/test_functools.py
 python/branches/py3k-short-float-repr/Lib/test/test_gc.py
 python/branches/py3k-short-float-repr/Lib/test/test_grp.py
 python/branches/py3k-short-float-repr/Lib/test/test_http_cookiejar.py
 python/branches/py3k-short-float-repr/Lib/test/test_http_cookies.py
 python/branches/py3k-short-float-repr/Lib/test/test_imp.py
 python/branches/py3k-short-float-repr/Lib/test/test_io.py
 python/branches/py3k-short-float-repr/Lib/test/test_ioctl.py
 python/branches/py3k-short-float-repr/Lib/test/test_locale.py
 python/branches/py3k-short-float-repr/Lib/test/test_logging.py
 python/branches/py3k-short-float-repr/Lib/test/test_mailbox.py
 python/branches/py3k-short-float-repr/Lib/test/test_mmap.py
 python/branches/py3k-short-float-repr/Lib/test/test_multibytecodec.py
 python/branches/py3k-short-float-repr/Lib/test/test_multiprocessing.py
 python/branches/py3k-short-float-repr/Lib/test/test_nis.py
 python/branches/py3k-short-float-repr/Lib/test/test_ossaudiodev.py
 python/branches/py3k-short-float-repr/Lib/test/test_posix.py
 python/branches/py3k-short-float-repr/Lib/test/test_pty.py
 python/branches/py3k-short-float-repr/Lib/test/test_pwd.py
 python/branches/py3k-short-float-repr/Lib/test/test_resource.py
 python/branches/py3k-short-float-repr/Lib/test/test_scope.py
 python/branches/py3k-short-float-repr/Lib/test/test_sqlite.py
 python/branches/py3k-short-float-repr/Lib/test/test_startfile.py
 python/branches/py3k-short-float-repr/Lib/test/test_struct.py
 python/branches/py3k-short-float-repr/Lib/test/test_sundry.py
 python/branches/py3k-short-float-repr/Lib/test/test_symtable.py
 python/branches/py3k-short-float-repr/Lib/test/test_sys.py
 python/branches/py3k-short-float-repr/Lib/test/test_syslog.py
 python/branches/py3k-short-float-repr/Lib/test/test_tcl.py
 python/branches/py3k-short-float-repr/Lib/test/test_time.py
 python/branches/py3k-short-float-repr/Lib/test/test_tk.py
 python/branches/py3k-short-float-repr/Lib/test/test_ttk_guionly.py
 python/branches/py3k-short-float-repr/Lib/test/test_ttk_textonly.py
 python/branches/py3k-short-float-repr/Lib/test/test_types.py
 python/branches/py3k-short-float-repr/Lib/test/test_unittest.py
 python/branches/py3k-short-float-repr/Lib/test/test_urllib.py
 python/branches/py3k-short-float-repr/Lib/test/test_urllib2.py
 python/branches/py3k-short-float-repr/Lib/test/test_urllib2net.py
 python/branches/py3k-short-float-repr/Lib/test/test_urlparse.py
 python/branches/py3k-short-float-repr/Lib/test/test_wait4.py
 python/branches/py3k-short-float-repr/Lib/test/test_warnings.py
 python/branches/py3k-short-float-repr/Lib/test/test_winreg.py
 python/branches/py3k-short-float-repr/Lib/test/test_winsound.py
 python/branches/py3k-short-float-repr/Lib/test/test_xml_etree_c.py
 python/branches/py3k-short-float-repr/Lib/test/test_xmlrpc.py
 python/branches/py3k-short-float-repr/Lib/test/test_zlib.py
 python/branches/py3k-short-float-repr/Lib/timeit.py
 python/branches/py3k-short-float-repr/Lib/trace.py
 python/branches/py3k-short-float-repr/Lib/unittest.py
 python/branches/py3k-short-float-repr/Lib/urllib/parse.py
 python/branches/py3k-short-float-repr/Lib/urllib/request.py
 python/branches/py3k-short-float-repr/Lib/xmlrpc/client.py
 python/branches/py3k-short-float-repr/Lib/xmlrpc/server.py
 python/branches/py3k-short-float-repr/Mac/BuildScript/README.txt
 python/branches/py3k-short-float-repr/Mac/BuildScript/build-installer.py
 python/branches/py3k-short-float-repr/Mac/BuildScript/resources/ReadMe.txt
 python/branches/py3k-short-float-repr/Mac/Makefile.in
 python/branches/py3k-short-float-repr/Mac/PythonLauncher/FileSettings.m
 python/branches/py3k-short-float-repr/Mac/Resources/app/Info.plist.in
 python/branches/py3k-short-float-repr/Makefile.pre.in
 python/branches/py3k-short-float-repr/Misc/ACKS
 python/branches/py3k-short-float-repr/Misc/NEWS
 python/branches/py3k-short-float-repr/Misc/RPM/python-3.1.spec
 python/branches/py3k-short-float-repr/Modules/Setup.dist
 python/branches/py3k-short-float-repr/Modules/_cursesmodule.c
 python/branches/py3k-short-float-repr/Modules/_functoolsmodule.c
 python/branches/py3k-short-float-repr/Modules/_multiprocessing/multiprocessing.h
 python/branches/py3k-short-float-repr/Modules/_multiprocessing/semaphore.c
 python/branches/py3k-short-float-repr/Modules/_multiprocessing/win32_functions.c
 python/branches/py3k-short-float-repr/Modules/_pickle.c
 python/branches/py3k-short-float-repr/Modules/arraymodule.c
 python/branches/py3k-short-float-repr/Modules/cjkcodecs/multibytecodec.c
 python/branches/py3k-short-float-repr/Modules/mmapmodule.c
 python/branches/py3k-short-float-repr/Modules/socketmodule.c
 python/branches/py3k-short-float-repr/Objects/bytearrayobject.c
 python/branches/py3k-short-float-repr/Objects/bytesobject.c
 python/branches/py3k-short-float-repr/Objects/exceptions.c
 python/branches/py3k-short-float-repr/Objects/longobject.c
 python/branches/py3k-short-float-repr/Objects/stringlib/formatter.h
 python/branches/py3k-short-float-repr/Objects/stringlib/localeutil.h
 python/branches/py3k-short-float-repr/Objects/stringlib/stringdefs.h
 python/branches/py3k-short-float-repr/Objects/stringlib/unicodedefs.h
 python/branches/py3k-short-float-repr/Objects/unicodeobject.c
 python/branches/py3k-short-float-repr/PC/VC6/pythoncore.dsp
 python/branches/py3k-short-float-repr/PC/VS7.1/pythoncore.vcproj
 python/branches/py3k-short-float-repr/PC/VS8.0/pythoncore.vcproj
 python/branches/py3k-short-float-repr/PCbuild/pythoncore.vcproj
 python/branches/py3k-short-float-repr/Parser/parser.c
 python/branches/py3k-short-float-repr/Parser/parsetok.c
 python/branches/py3k-short-float-repr/Parser/tokenizer.c
 python/branches/py3k-short-float-repr/Python/_warnings.c
 python/branches/py3k-short-float-repr/Python/future.c
 python/branches/py3k-short-float-repr/Python/getargs.c
 python/branches/py3k-short-float-repr/Python/graminit.c
 python/branches/py3k-short-float-repr/Python/import.c
 python/branches/py3k-short-float-repr/Python/modsupport.c
 python/branches/py3k-short-float-repr/Python/pystrtod.c
 python/branches/py3k-short-float-repr/Python/pythonrun.c
 python/branches/py3k-short-float-repr/Python/symtable.c
 python/branches/py3k-short-float-repr/README
 python/branches/py3k-short-float-repr/Tools/buildbot/test.bat
 python/branches/py3k-short-float-repr/Tools/msi/msi.py
 python/branches/py3k-short-float-repr/Tools/msi/msilib.py
 python/branches/py3k-short-float-repr/Tools/scripts/reindent-rst.py
 python/branches/py3k-short-float-repr/setup.py
Modified: python/branches/py3k-short-float-repr/Demo/distutils/test2to3/setup.py
==============================================================================
--- python/branches/py3k-short-float-repr/Demo/distutils/test2to3/setup.py	(original)
+++ python/branches/py3k-short-float-repr/Demo/distutils/test2to3/setup.py	Sun Apr 5 01:04:14 2009
@@ -20,7 +20,7 @@
 license = "PSF license",
 packages = ["test2to3"],
 scripts = ["maintest.py"],
- cmdclass = {'build_py':build_py,
- 'build_scripts':build_scripts,
+ cmdclass = {'build_py': build_py,
+ 'build_scripts': build_scripts,
 }
 )
Modified: python/branches/py3k-short-float-repr/Doc/c-api/arg.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/c-api/arg.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/c-api/arg.rst	Sun Apr 5 01:04:14 2009
@@ -208,9 +208,13 @@
 Convert a Python 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
+ Convert a Python character, represented as a byte string of length 1, to a C
 :ctype:`char`.
 
+``C`` (string of length 1) [int]
+ Convert a Python character, represented as a unicode string of length 1, to a
+ C :ctype:`int`.
+
 ``f`` (float) [float]
 Convert a Python floating point number to a C :ctype:`float`.
 
@@ -507,8 +511,12 @@
 Convert a C :ctype:`Py_ssize_t` to a Python integer.
 
 ``c`` (string of length 1) [char]
- Convert a C :ctype:`int` representing a character to a Python string of length
- 1.
+ Convert a C :ctype:`int` representing a byte to a Python byte string of
+ length 1.
+
+ ``C`` (string of length 1) [int]
+ Convert a C :ctype:`int` representing a character to Python unicode
+ string of length 1.
 
 ``d`` (float) [double]
 Convert a C :ctype:`double` to a Python floating point number.
Modified: python/branches/py3k-short-float-repr/Doc/c-api/exceptions.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/c-api/exceptions.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/c-api/exceptions.rst	Sun Apr 5 01:04:14 2009
@@ -400,6 +400,52 @@
 the warning message.
 
 
+Exception Objects
+=================
+
+.. cfunction:: PyObject* PyException_GetTraceback(PyObject *ex)
+
+ Return the traceback associated with the exception as a new reference, as
+ accessible from Python through :attr:`__traceback__`. If there is no
+ traceback associated, this returns *NULL*.
+
+
+.. cfunction:: int PyException_SetTraceback(PyObject *ex, PyObject *tb)
+
+ Set the traceback associated with the exception to *tb*. Use ``Py_None`` to
+ clear it.
+
+
+.. cfunction:: PyObject* PyException_GetContext(PyObject *ex)
+
+ Return the context (another exception instance during whose handling *ex* was
+ raised) associated with the exception as a new reference, as accessible from
+ Python through :attr:`__context__`. If there is no context associated, this
+ returns *NULL*.
+
+
+.. cfunction:: void PyException_SetContext(PyObject *ex, PyObject *ctx)
+
+ Set the context associated with the exception to *ctx*. Use *NULL* to clear
+ it. There is no type check to make sure that *ctx* is an exception instance.
+ This steals a reference to *ctx*.
+
+
+.. cfunction:: PyObject* PyException_GetCause(PyObject *ex)
+
+ Return the cause (another exception instance set by ``raise ... from ...``)
+ associated with the exception as a new reference, as accessible from Python
+ through :attr:`__cause__`. If there is no cause associated, this returns
+ *NULL*.
+
+
+.. cfunction:: void PyException_SetCause(PyObject *ex, PyObject *ctx)
+
+ Set the cause associated with the exception to *ctx*. Use *NULL* to clear
+ it. There is no type check to make sure that *ctx* is an exception instance.
+ This steals a reference to *ctx*.
+
+
 .. _standardexceptions:
 
 Standard Exceptions
Modified: python/branches/py3k-short-float-repr/Doc/c-api/import.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/c-api/import.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/c-api/import.rst	Sun Apr 5 01:04:14 2009
@@ -200,7 +200,7 @@
 tricks with this to provide a dynamically created collection of frozen modules.
 
 
-.. cfunction:: int PyImport_AppendInittab(char *name, PyObject* (*initfunc)(void))
+.. cfunction:: int PyImport_AppendInittab(const char *name, PyObject* (*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
Modified: python/branches/py3k-short-float-repr/Doc/c-api/long.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/c-api/long.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/c-api/long.rst	Sun Apr 5 01:04:14 2009
@@ -133,9 +133,9 @@
 single: PY_SSIZE_T_MAX
 single: OverflowError (built-in exception)
 
- Return a C :ctype:`Py_ssize_t` representation of the contents of *pylong*. If
- *pylong* is greater than :const:`PY_SSIZE_T_MAX`, an :exc:`OverflowError` is raised
- and ``-1`` will be returned.
+ Return a C :ctype:`Py_ssize_t` representation of the contents of *pylong*.
+ If *pylong* is greater than :const:`PY_SSIZE_T_MAX`, an :exc:`OverflowError`
+ is raised and ``-1`` will be returned.
 
 
 .. cfunction:: unsigned long PyLong_AsUnsignedLong(PyObject *pylong)
@@ -149,16 +149,6 @@
 raised.
 
 
-.. cfunction:: Py_ssize_t PyLong_AsSsize_t(PyObject *pylong)
-
- .. index::
- single: PY_SSIZE_T_MAX
-
- Return a :ctype:`Py_ssize_t` representation of the contents of *pylong*. If
- *pylong* is greater than :const:`PY_SSIZE_T_MAX`, an :exc:`OverflowError` is
- raised.
-
-
 .. cfunction:: size_t PyLong_AsSize_t(PyObject *pylong)
 
 Return a :ctype:`size_t` representation of the contents of *pylong*. If
Modified: python/branches/py3k-short-float-repr/Doc/distutils/setupscript.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/distutils/setupscript.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/distutils/setupscript.rst	Sun Apr 5 01:04:14 2009
@@ -334,6 +334,10 @@
 
 There are still some other options which can be used to handle special cases.
 
+The :option:`optional` option is a boolean; if it is true, that specifies that
+a build failure in the extension should not abort the build process, but simply
+not install the failing extension.
+
 The :option:`extra_objects` option is a list of object files to be passed to the
 linker. These files must not have extensions, as the default extension for the
 compiler is used.
Modified: python/branches/py3k-short-float-repr/Doc/extending/extending.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/extending/extending.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/extending/extending.rst	Sun Apr 5 01:04:14 2009
@@ -1266,12 +1266,13 @@
 {
 PyObject *m;
 
- m = Py_InitModule("client", ClientMethods);
+ m = PyModule_Create(&clientmodule);
 if (m == NULL)
- return;
+ return NULL;
 if (import_spam() < 0)
- return;
+ return NULL;
 /* additional initialization can happen here */
+ return m;
 }
 
 The main disadvantage of this approach is that the file :file:`spammodule.h` is
Modified: python/branches/py3k-short-float-repr/Doc/extending/newtypes.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/extending/newtypes.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/extending/newtypes.rst	Sun Apr 5 01:04:14 2009
@@ -871,6 +871,7 @@
 
 Py_INCREF(&ShoddyType);
 PyModule_AddObject(m, "Shoddy", (PyObject *) &ShoddyType);
+ return m;
 }
 
 Before calling :cfunc:`PyType_Ready`, the type structure must have the
@@ -1230,50 +1231,53 @@
 return -1;
 }
 
-.. XXX tp_compare is dead; need to rewrite for tp_richcompare!
+Object Comparison
+-----------------
 
- Object Comparison
- -----------------
+::
+
+ richcmpfunc tp_richcompare;
+
+The :attr:`tp_richcompare` handler is called when comparisons are needed. It is
+analogous to the :ref:`rich comparison methods <richcmpfuncs>`, like
+:meth:`__lt__`, and also called by :cfunc:`PyObject_RichCompare` and
+:cfunc:`PyObject_RichCompareBool`.
+
+This function is called with two Python objects and the operator as arguments,
+where the operator is one of ``Py_EQ``, ``Py_NE``, ``Py_LE``, ``Py_GT``,
+``Py_LT`` or ``Py_GT``. It should compare the two objects with respect to the
+specified operator and return ``Py_True`` or ``Py_False`` if the comparison is
+successfull, ``Py_NotImplemented`` to indicate that comparison is not
+implemented and the other object's comparison method should be tried, or *NULL*
+if an exception was set.
+
+Here is a sample implementation, for a datatype that is considered equal if the
+size of an internal pointer is equal::
+
+ static int
+ newdatatype_richcmp(PyObject *obj1, PyObject *obj2, int op)
+ {
+ PyObject *result;
+ int c, size1, size2;
 
- ::
+ /* code to make sure that both arguments are of type
+ newdatatype omitted */
 
- cmpfunc tp_compare;
+ size1 = obj1->obj_UnderlyingDatatypePtr->size;
+ size2 = obj2->obj_UnderlyingDatatypePtr->size;
 
- The :attr:`tp_compare` handler is called when comparisons are needed and the
- object does not implement the specific rich comparison method which matches the
- requested comparison. (It is always used if defined and the
- :cfunc:`PyObject_Compare` or :cfunc:`PyObject_Cmp` functions are used, or if
- :func:`cmp` is used from Python.) It is analogous to the :meth:`__cmp__` method.
- This function should return ``-1`` if *obj1* is less than *obj2*, ``0`` if they
- are equal, and ``1`` if *obj1* is greater than *obj2*. (It was previously
- allowed to return arbitrary negative or positive integers for less than and
- greater than, respectively; as of Python 2.2, this is no longer allowed. In the
- future, other return values may be assigned a different meaning.)
-
- A :attr:`tp_compare` handler may raise an exception. In this case it should
- return a negative value. The caller has to test for the exception using
- :cfunc:`PyErr_Occurred`.
-
- Here is a sample implementation::
-
- static int
- newdatatype_compare(newdatatypeobject * obj1, newdatatypeobject * obj2)
- {
- long result;
-
- if (obj1->obj_UnderlyingDatatypePtr->size <
- obj2->obj_UnderlyingDatatypePtr->size) {
- result = -1;
- }
- else if (obj1->obj_UnderlyingDatatypePtr->size >
- obj2->obj_UnderlyingDatatypePtr->size) {
- result = 1;
- }
- else {
- result = 0;
- }
- return result;
- }
+ switch (op) {
+ case Py_LT: c = size1 < size2; break;
+ case Py_LE: c = size1 <= size2; break;
+ case Py_EQ: c = size1 == size2; break;
+ case Py_NE: c = size1 != size2; break;
+ case Py_GT: c = size1 > size2; break;
+ case Py_GE: c = size1 >= size2; break;
+ }
+ result = c ? Py_True : Py_False;
+ Py_INCREF(result);
+ return result;
+ }
 
 
 Abstract Protocol Support
Modified: python/branches/py3k-short-float-repr/Doc/howto/regex.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/howto/regex.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/howto/regex.rst	Sun Apr 5 01:04:14 2009
@@ -540,6 +540,10 @@
 | :const:`VERBOSE`, :const:`X` | Enable verbose REs, which can be organized |
 | | more cleanly and understandably. |
 +---------------------------------+--------------------------------------------+
+| :const:`ASCII`, :const:`A` | Makes several escapes like ``\w``, ``\b``, |
+| | ``\s`` and ``\d`` match only on ASCII |
+| | characters with the respective property. |
++---------------------------------+--------------------------------------------+
 
 
 .. data:: I
@@ -594,6 +598,15 @@
 newline; without this flag, ``'.'`` will match anything *except* a newline.
 
 
+.. data:: A
+ ASCII
+ :noindex:
+
+ Make ``\w``, ``\W``, ``\b``, ``\B``, ``\s`` and ``\S`` perform ASCII-only
+ matching instead of full Unicode matching. This is only meaningful for
+ Unicode patterns, and is ignored for byte patterns.
+
+
 .. data:: X
 VERBOSE
 :noindex:
Modified: python/branches/py3k-short-float-repr/Doc/library/abc.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/abc.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/abc.rst	Sun Apr 5 01:04:14 2009
@@ -158,7 +158,7 @@
 multiple-inheritance.
 
 
-.. function:: abstractproperty(fget[, fset[, fdel[, doc]]])
+.. function:: abstractproperty(fget=None, fset=None, fdel=None, doc=None)
 
 A subclass of the built-in :func:`property`, indicating an abstract property.
 
Modified: python/branches/py3k-short-float-repr/Doc/library/aifc.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/aifc.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/aifc.rst	Sun Apr 5 01:04:14 2009
@@ -37,7 +37,7 @@
 Module :mod:`aifc` defines the following function:
 
 
-.. function:: open(file[, mode])
+.. function:: open(file, mode=None)
 
 Open an AIFF or AIFF-C file and return an object instance with methods that are
 described below. The argument *file* is either a string naming a file or a file
Modified: python/branches/py3k-short-float-repr/Doc/library/asynchat.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/asynchat.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/asynchat.rst	Sun Apr 5 01:04:14 2009
@@ -202,7 +202,7 @@
 ------------------------------------------
 
 
-.. class:: simple_producer(data[, buffer_size=512])
+.. 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
@@ -215,7 +215,7 @@
 empty string.
 
 
-.. class:: fifo([list=None])
+.. 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
Modified: python/branches/py3k-short-float-repr/Doc/library/atexit.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/atexit.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/atexit.rst	Sun Apr 5 01:04:14 2009
@@ -17,7 +17,7 @@
 :func:`os._exit` is called.
 
 
-.. function:: register(func[, *args[, **kargs]])
+.. function:: register(func, *args, **kargs)
 
 Register *func* as a function to be executed at termination. Any optional
 arguments that are to be passed to *func* must be passed as arguments to
@@ -48,7 +48,8 @@
 .. seealso::
 
 Module :mod:`readline`
- Useful example of :mod:`atexit` to read and write :mod:`readline` history files.
+ Useful example of :mod:`atexit` to read and write :mod:`readline` history
+ files.
 
 
 .. _atexit-example:
Modified: python/branches/py3k-short-float-repr/Doc/library/base64.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/base64.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/base64.rst	Sun Apr 5 01:04:14 2009
@@ -23,7 +23,7 @@
 
 The modern interface provides:
 
-.. function:: b64encode(s[, altchars])
+.. function:: b64encode(s, altchars=None)
 
 Encode a string use Base64.
 
@@ -36,7 +36,7 @@
 The encoded string is returned.
 
 
-.. function:: b64decode(s[, altchars])
+.. function:: b64decode(s, altchars=None)
 
 Decode a Base64 encoded string.
 
@@ -78,7 +78,7 @@
 is returned.
 
 
-.. function:: b32decode(s[, casefold[, map01]])
+.. function:: b32decode(s, casefold=False, map01=None)
 
 Decode a Base32 encoded string.
 
@@ -105,7 +105,7 @@
 *s* is the string to encode. The encoded string is returned.
 
 
-.. function:: b16decode(s[, casefold])
+.. function:: b16decode(s, casefold=False)
 
 Decode a Base16 encoded string.
 
Modified: python/branches/py3k-short-float-repr/Doc/library/bdb.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/bdb.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/bdb.rst	Sun Apr 5 01:04:14 2009
@@ -16,7 +16,7 @@
 
 The :mod:`bdb` module also defines two classes:
 
-.. class:: Breakpoint(self, file, line[, temporary=0[, cond=None [, funcname=None]]])
+.. class:: Breakpoint(self, file, line, temporary=0, cond=None, funcname=None)
 
 This class implements temporary breakpoints, ignore counts, disabling and
 (re-)enabling, and conditionals.
@@ -50,7 +50,7 @@
 Mark the breakpoint as disabled.
 
 
- .. method:: pprint([out])
+ .. method:: bpprint(out=None)
 
 Print all the information about the breakpoint:
 
@@ -233,7 +233,7 @@
 breakpoints. These methods return a string containing an error message if
 something went wrong, or ``None`` if all is well.
 
- .. method:: set_break(filename, lineno[, temporary=0[, cond[, funcname]]])
+ .. method:: 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*
@@ -285,7 +285,7 @@
 Get a list of records for a frame and all higher (calling) and lower
 frames, and the size of the higher part.
 
- .. method:: format_stack_entry(frame_lineno, [lprefix=': '])
+ .. method:: format_stack_entry(frame_lineno, lprefix=': ')
 
 Return a string with information about a stack entry, identified by a
 ``(frame, lineno)`` tuple:
@@ -300,12 +300,12 @@
 The following two methods can be called by clients to use a debugger to debug
 a :term:`statement`, given as a string.
 
- .. method:: run(cmd, [globals, [locals]])
+ .. method:: run(cmd, globals=None, locals=None)
 
 Debug a statement executed via the :func:`exec` function. *globals*
 defaults to :attr:`__main__.__dict__`, *locals* defaults to *globals*.
 
- .. method:: runeval(expr, [globals, [locals]])
+ .. method:: runeval(expr, globals=None, locals=None)
 
 Debug an expression executed via the :func:`eval` function. *globals* and
 *locals* have the same meaning as in :meth:`run`.
Modified: python/branches/py3k-short-float-repr/Doc/library/binascii.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/binascii.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/binascii.rst	Sun Apr 5 01:04:14 2009
@@ -49,14 +49,14 @@
 should be at most 57 to adhere to the base64 standard.
 
 
-.. function:: a2b_qp(string[, header])
+.. function:: a2b_qp(string, header=False)
 
 Convert a block of quoted-printable data back to binary and return the binary
 data. More than one line may be passed at a time. If the optional argument
 *header* is present and true, underscores will be decoded as spaces.
 
 
-.. function:: b2a_qp(data[, quotetabs, istext, header])
+.. function:: b2a_qp(data, quotetabs=False, istext=True, header=False)
 
 Convert binary data to a line(s) of ASCII characters in quoted-printable
 encoding. The return value is the converted line(s). If the optional argument
Modified: python/branches/py3k-short-float-repr/Doc/library/collections.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/collections.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/collections.rst	Sun Apr 5 01:04:14 2009
@@ -442,6 +442,29 @@
 
 This section shows various approaches to working with deques.
 
+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)
+
+Another approach to using deques is to maintain a sequence of recently
+added elements by appending to the right and popping to the left::
+
+ def moving_average(iterable, n=3):
+ # moving_average([40, 30, 50, 46, 39, 44]) --> 40.0 42.0 45.0 43.0
+ # http://en.wikipedia.org/wiki/Moving_average
+ it = iter(iterable)
+ d = deque(itertools.islice(it, n))
+ s = sum(d)
+ if len(d) == n:
+ yield s / n
+ for elem in it:
+ s += elem - d.popleft()
+ d.append(elem)
+ yield s / n
+
 The :meth:`rotate` method provides a way to implement :class:`deque` slicing and
 deletion. For example, a pure python implementation of ``del d[n]`` relies on
 the :meth:`rotate` method to position elements to be popped::
@@ -459,31 +482,6 @@
 stack manipulations such as ``dup``, ``drop``, ``swap``, ``over``, ``pick``,
 ``rot``, and ``roll``.
 
-Multi-pass data reduction algorithms can be succinctly expressed and efficiently
-coded by extracting elements with multiple calls to :meth:`popleft`, applying
-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:
-
- >>> def maketree(iterable):
- ... d = deque(iterable)
- ... while len(d) > 1:
- ... pair = [d.popleft(), d.popleft()]
- ... d.append(pair)
- ... return list(d)
- ...
- >>> 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)
-
 
 :class:`defaultdict` objects
 ----------------------------
@@ -627,7 +625,7 @@
 
 If *rename* is true, invalid fieldnames are automatically replaced
 with positional names. For example, ``['abc', 'def', 'ghi', 'abc']`` is
- converted to ``['abc', '_2', 'ghi', '_4']``, eliminating the keyword
+ converted to ``['abc', '_1', 'ghi', '_3']``, eliminating the keyword
 ``def`` and the duplicate fieldname ``abc``.
 
 If *verbose* is true, the class definition is printed just before being built.
Modified: python/branches/py3k-short-float-repr/Doc/library/csv.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/csv.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/csv.rst	Sun Apr 5 01:04:14 2009
@@ -33,14 +33,6 @@
 write sequences. Programmers can also read and write data in dictionary form
 using the :class:`DictReader` and :class:`DictWriter` classes.
 
-.. note::
-
- This version of the :mod:`csv` module doesn't support Unicode input. Also,
- there are currently some issues regarding ASCII NUL characters. Accordingly,
- all input should be UTF-8 or printable ASCII to be safe; see the examples in
- section :ref:`csv-examples`. These restrictions will be removed in the future.
-
-
 .. seealso::
 
 :pep:`305` - CSV File API
@@ -60,8 +52,8 @@
 Return a reader object which will iterate over lines in the given *csvfile*.
 *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
+ objects are both suitable. If *csvfile* is a file object, it should be opened
+ with ``newline=''``. [#]_ An optional
 *dialect* parameter can be given which is used to define a set of parameters
 specific to a particular CSV dialect. It may be an instance of a subclass of
 the :class:`Dialect` class or one of the strings returned by the
@@ -71,20 +63,13 @@
 section :ref:`csv-fmt-params`.
 
 Each row read from the csv file is returned as a list of strings. No
- automatic data type conversion is performed.
-
- The parser is quite strict with respect to multi-line quoted fields. Previously,
- if a line ended within a quoted field without a terminating newline character, a
- newline would be inserted into the returned field. This behavior caused problems
- when reading files which contained carriage return characters within fields.
- The behavior was changed to return the field without inserting newlines. As a
- consequence, if newlines embedded within fields are important, the input should
- be split into lines in a manner which preserves the newline characters.
+ automatic data type conversion is performed unless the ``QUOTE_NONNUMERIC`` format
+ option is specified (in which case unquoted fields are transformed into floats).
 
 A short usage example::
 
 >>> import csv
- >>> spamReader = csv.reader(open('eggs.csv'), delimiter=' ', quotechar='|')
+ >>> spamReader = csv.reader(open('eggs.csv', newline=''), delimiter=' ', quotechar='|')
 >>> for row in spamReader:
 ... print(', '.join(row))
 Spam, Spam, Spam, Spam, Spam, Baked Beans
@@ -95,8 +80,7 @@
 
 Return a writer object responsible for converting the user's data into delimited
 strings on the given file-like object. *csvfile* can be any object with a
- :func:`write` method. If *csvfile* is a file object, it must be opened with the
- 'b' flag on platforms where that makes a difference. An optional *dialect*
+ :func:`write` method. An optional *dialect*
 parameter can be given which is used to define a set of parameters specific to a
 particular CSV dialect. It may be an instance of a subclass of the
 :class:`Dialect` class or one of the strings returned by the
@@ -270,7 +254,6 @@
 
 Raised by any of the functions when an error is detected.
 
-
 .. _csv-fmt-params:
 
 Dialects and Formatting Parameters
@@ -351,14 +334,13 @@
 Reader objects (:class:`DictReader` instances and objects returned by the
 :func:`reader` function) have the following public methods:
 
-
-.. method:: csvreader.next()
+.. method:: csvreader.__next__()
 
 Return the next row of the reader's iterable object as a list, parsed according
- to the current dialect.
+ to the current dialect. Usually you should call this as ``next(reader)``.
 
-Reader objects have the following public attributes:
 
+Reader objects have the following public attributes:
 
 .. attribute:: csvreader.dialect
 
@@ -371,10 +353,8 @@
 number of records returned, as records can span multiple lines.
 
 
-
 DictReader objects have the following public attribute:
 
-
 .. attribute:: csvreader.fieldnames
 
 If not passed as a parameter when creating the object, this attribute is
@@ -422,41 +402,52 @@
 The simplest example of reading a CSV file::
 
 import csv
- reader = csv.reader(open("some.csv", "rb"))
+ reader = csv.reader(open("some.csv", newline=''))
 for row in reader:
 print(row)
 
 Reading a file with an alternate format::
 
 import csv
- reader = csv.reader(open("passwd", "rb"), delimiter=':', quoting=csv.QUOTE_NONE)
+ reader = csv.reader(open("passwd"), delimiter=':', quoting=csv.QUOTE_NONE)
 for row in reader:
 print(row)
 
 The corresponding simplest possible writing example is::
 
 import csv
- writer = csv.writer(open("some.csv", "wb"))
+ writer = csv.writer(open("some.csv", "w"))
 writer.writerows(someiterable)
 
+Since :func:`open` is used to open a CSV file for reading, the file
+will by default be decoded into unicode using the system default
+encoding (see :func:`locale.getpreferredencoding`). To decode a file
+using a different encoding, use the ``encoding`` argument of open::
+
+ import csv
+ reader = csv.reader(open("some.csv", newline='', encoding='utf-8'))
+ for row in reader:
+ print(row)
+
+The same applies to writing in something other than the system default
+encoding: specify the encoding argument when opening the output file.
+
 Registering a new dialect::
 
 import csv
-
 csv.register_dialect('unixpwd', delimiter=':', quoting=csv.QUOTE_NONE)
-
- reader = csv.reader(open("passwd", "rb"), 'unixpwd')
+ reader = csv.reader(open("passwd"), 'unixpwd')
 
 A slightly more advanced use of the reader --- catching and reporting errors::
 
 import csv, sys
 filename = "some.csv"
- reader = csv.reader(open(filename, "rb"))
+ reader = csv.reader(open(filename, newline=''))
 try:
 for row in reader:
 print(row)
 except csv.Error as e:
- sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
+ sys.exit('file {}, line {}: {}'.format(filename, reader.line_num, e))
 
 And while the module doesn't directly support parsing strings, it can easily be
 done::
@@ -465,94 +456,10 @@
 for row in csv.reader(['one,two,three']):
 print(row)
 
-The :mod:`csv` module doesn't directly support reading and writing Unicode, but
-it is 8-bit-clean save for some problems with ASCII NUL characters. So you can
-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 :term:`generator` that wraps :class:`csv.reader`
-to handle Unicode CSV data (a list of Unicode strings). :func:`utf_8_encoder`
-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::
-
- import csv
 
- def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
- # csv.py doesn't do Unicode; encode temporarily as UTF-8:
- csv_reader = csv.reader(utf_8_encoder(unicode_csv_data),
- dialect=dialect, **kwargs)
- for row in csv_reader:
- # decode UTF-8 back to Unicode, cell by cell:
- yield [unicode(cell, 'utf-8') for cell in row]
-
- def utf_8_encoder(unicode_csv_data):
- for line in unicode_csv_data:
- yield line.encode('utf-8')
-
-For all other encodings the following :class:`UnicodeReader` and
-:class:`UnicodeWriter` classes can be used. They take an additional *encoding*
-parameter in their constructor and make sure that the data passes the real
-reader or writer encoded as UTF-8::
-
- import csv, codecs, io
-
- class UTF8Recoder:
- """
- Iterator that reads an encoded stream and reencodes the input to UTF-8
- """
- def __init__(self, f, encoding):
- self.reader = codecs.getreader(encoding)(f)
-
- def __iter__(self):
- return self
-
- def __next__(self):
- return next(self.reader).encode("utf-8")
-
- class UnicodeReader:
- """
- A CSV reader which will iterate over lines in the CSV file "f",
- which is encoded in the given encoding.
- """
-
- def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
- f = UTF8Recoder(f, encoding)
- self.reader = csv.reader(f, dialect=dialect, **kwds)
-
- def __next__(self):
- row = next(self.reader)
- return [unicode(s, "utf-8") for s in row]
-
- def __iter__(self):
- return self
-
- class UnicodeWriter:
- """
- A CSV writer which will write rows to CSV file "f",
- which is encoded in the given encoding.
- """
-
- def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
- # Redirect output to a queue
- self.queue = io.StringIO()
- self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
- self.stream = f
- self.encoder = codecs.getincrementalencoder(encoding)()
-
- def writerow(self, row):
- self.writer.writerow([s.encode("utf-8") for s in row])
- # Fetch UTF-8 output from the queue ...
- data = self.queue.getvalue()
- data = data.decode("utf-8")
- # ... and reencode it into the target encoding
- data = self.encoder.encode(data)
- # write to the target stream
- self.stream.write(data)
- # empty queue
- self.queue.truncate(0)
-
- def writerows(self, rows):
- for row in rows:
- self.writerow(row)
+.. rubric:: Footnotes
 
+.. [#] If ``newline=''`` is not specified, newlines embedded inside quoted fields
+ will not be interpreted correctly. It should always be safe to specify
+ ``newline=''``, since the csv module does its own universal newline handling
+ on input.
Modified: python/branches/py3k-short-float-repr/Doc/library/datetime.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/datetime.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/datetime.rst	Sun Apr 5 01:04:14 2009
@@ -1621,8 +1621,12 @@
 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.
+ The range really is ``0`` to ``61``; according to the Posix standard this
+ accounts for leap seconds and the (very rare) double leap seconds.
+ The :mod:`time` module may produce and does accept leap seconds since
+ it is based on the Posix standard, but the :mod:`datetime` module
+ does not accept leap seconds in :func:`strptime` input nor will it
+ produce them in :func:`strftime` output.
 
 (4)
 When used with the :func:`strptime` function, ``%U`` and ``%W`` are only used in
Modified: python/branches/py3k-short-float-repr/Doc/library/email.header.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/email.header.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/email.header.rst	Sun Apr 5 01:04:14 2009
@@ -72,7 +72,7 @@
 
 Optional *continuation_ws* must be :rfc:`2822`\ -compliant folding whitespace,
 and is usually either a space or a hard tab character. This character will be
- prepended to continuation lines.
+ prepended to continuation lines. *continuation_ws* defaults to a single space character (" ").
 
 Optional *errors* is passed straight through to the :meth:`append` method.
 
Modified: python/branches/py3k-short-float-repr/Doc/library/functions.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/functions.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/functions.rst	Sun Apr 5 01:04:14 2009
@@ -334,12 +334,12 @@
 This function supports dynamic execution of Python code. *object* must be
 either a string or a code object. If it is a string, the string is parsed as
 a suite of Python statements which is then executed (unless a syntax error
- occurs). If it is a code object, it is simply executed. In all cases, the
- code that's executed is expected to be valid as file input (see the section
- "File input" in the Reference Manual). Be aware that the :keyword:`return`
- and :keyword:`yield` statements may not be used outside of function
- definitions even within the context of code passed to the :func:`exec`
- function. The return value is ``None``.
+ occurs). [#]_ If it is a code object, it is simply executed. In all cases,
+ the code that's executed is expected to be valid as file input (see the
+ section "File input" in the Reference Manual). Be aware that the
+ :keyword:`return` and :keyword:`yield` statements may not be used outside of
+ function definitions even within the context of code passed to the
+ :func:`exec` function. The return value is ``None``.
 
 In all cases, if the optional parts are omitted, the code is executed in the
 current scope. If only *globals* is provided, it must be a dictionary, which
@@ -1275,13 +1275,10 @@
 
 .. rubric:: Footnotes
 
-.. [#] Specifying a buffer size currently has no effect on systems that don't have
- :cfunc:`setvbuf`. The interface to specify the buffer size is not done using a
- method that calls :cfunc:`setvbuf`, because that may dump core when called after
- any I/O has been performed, and there's no reliable way to determine whether
- this is the case.
+.. [#] Note that the parser only accepts the Unix-style end of line convention.
+ If you are reading the code from a file, make sure to use newline conversion
+ mode to convert Windows or Mac-style newlines.
 
 .. [#] In the current implementation, local variable bindings cannot normally be
 affected this way, but variables retrieved from other scopes (such as modules)
 can be. This may change.
-
Modified: python/branches/py3k-short-float-repr/Doc/library/http.client.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/http.client.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/http.client.rst	Sun Apr 5 01:04:14 2009
@@ -59,8 +59,8 @@
 
 .. class:: HTTPResponse(sock[, debuglevel=0][, strict=0])
 
- Class whose instances are returned upon successful connection. Not instantiated
- directly by user.
+ Class whose instances are returned upon successful connection. Not
+ instantiated directly by user.
 
 
 The following exceptions are raised as appropriate:
@@ -433,7 +433,10 @@
 HTTPResponse Objects
 --------------------
 
-:class:`HTTPResponse` instances have the following methods and attributes:
+An :class:`HTTPResponse` instance wraps the HTTP response from the
+server. It provides access to the request headers and the entity
+body. The response is an iterable object and can be used in a with
+statement.
 
 
 .. method:: HTTPResponse.read([amt])
@@ -454,7 +457,9 @@
 
 .. attribute:: HTTPResponse.msg
 
- An :class:`email.message.Message` instance containing the response headers.
+ A :class:`http.client.HTTPMessage` instance containing the response
+ headers. :class:`http.client.HTTPMessage` is a subclass of
+ :class:`email.message.Message`.
 
 
 .. attribute:: HTTPResponse.version
@@ -472,6 +477,12 @@
 Reason phrase returned by server.
 
 
+.. attribute:: HTTPResponse.debuglevel
+
+ A debugging hook. If `debuglevel` is greater than zero, messages
+ will be printed to stdout as the response is read and parsed.
+
+
 Examples
 --------
 
@@ -505,3 +516,13 @@
 >>> data = response.read()
 >>> conn.close()
 
+
+.. _httpmessage-objects:
+
+HTTPMessage Objects
+-------------------
+
+An :class:`http.client.HTTPMessage` instance holds the headers from an HTTP
+response. It is implemented using the :class:`email.message.Message` class.
+
+.. XXX Define the methods that clients can depend upon between versions.
Modified: python/branches/py3k-short-float-repr/Doc/library/importlib.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/importlib.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/importlib.rst	Sun Apr 5 01:04:14 2009
@@ -37,7 +37,7 @@
 
 The :func:`.__import__` function
 The built-in function for which the :keyword:`import` statement is
- syntactic sugar for.
+ syntactic sugar.
 
 :pep:`235`
 Import on Case-Insensitive Platforms
@@ -71,16 +71,20 @@
 Import a module. The *name* argument specifies what module to
 import in absolute or relative terms
 (e.g. either ``pkg.mod`` or ``..mod``). If the name is
- specified in relative terms, then the *package* argument must be
- set to the package which is to act as the anchor for resolving the
+ specified in relative terms, then the *package* argument must be set to
+ the name of the package which is to act as the anchor for resolving the
 package name (e.g. ``import_module('..mod', 'pkg.subpkg')`` will import
 ``pkg.mod``).
 
 The :func:`import_module` function acts as a simplifying wrapper around
- :func:`__import__`. This means all semantics of the function are derived
- from :func:`__import__`, including requiring the package from which an
- import is occurring to have been previously imported (i.e., *package*
- must already be imported).
+ :func:`importlib.__import__`. This means all semantics of the function are
+ derived from :func:`importlib.__import__`, including requiring the package
+ from which an import is occurring to have been previously imported
+ (i.e., *package* must already be imported). The most important difference
+ is that :func:`import_module` returns the most nested package or module
+ that was imported (e.g. ``pkg.mod``), while :func:`__import__` returns the
+ top-level package or module (e.g. ``pkg``).
+
 
 :mod:`importlib.abc` -- Abstract base classes related to import
 ---------------------------------------------------------------
@@ -96,21 +100,21 @@
 .. class:: Finder
 
 An abstract base class representing a :term:`finder`.
+ See :pep:`302` for the exact definition for a finder.
 
 .. method:: find_module(fullname, path=None)
 
 An abstract method for finding a :term:`loader` for the specified
 module. If the :term:`finder` is found on :data:`sys.meta_path` and the
- module to be searched for is a subpackage or module then *path* is set
- to the value of :attr:`__path__` from the parent package. If a loader
+ module to be searched for is a subpackage or module then *path* will
+ be the value of :attr:`__path__` from the parent package. If a loader
 cannot be found, :keyword:`None` is returned.
 
- The exact definition of a :term:`finder` can be found in :pep:`302`.
-
 
 .. class:: Loader
 
 An abstract base class for a :term:`loader`.
+ See :pep:`302` for the exact definition for a loader.
 
 .. method:: load_module(fullname)
 
@@ -118,18 +122,19 @@
 loaded, :exc:`ImportError` is raised, otherwise the loaded module is
 returned.
 
- If the requested module is already exists in :data:`sys.modules`, that
+ If the requested module already exists in :data:`sys.modules`, that
 module should be used and reloaded.
- Otherwise a new module is to be created by the loader and inserted into
- :data:`sys.modules` before any loading begins to prevent recursion from
- the import. If the loader inserted into a module and the load fails it
+ Otherwise the loader should create a new module and insert it into
+ :data:`sys.modules` before any loading begins, to prevent recursion
+ from the import. If the loader inserted a module and the load fails, it
 must be removed by the loader from :data:`sys.modules`; modules already
 in :data:`sys.modules` before the loader began execution should be left
 alone. The :func:`importlib.util.module_for_loader` decorator handles
 all of these details.
 
- The loader is expected to set several attributes on the module when
- adding a new module to :data:`sys.modules`.
+ The loader should set several attributes on the module.
+ (Note that some of these attributes can change when a module is
+ reloaded.)
 
 - :attr:`__name__`
 The name of the module.
@@ -139,7 +144,7 @@
 modules).
 
 - :attr:`__path__`
- Set to a list of strings specifying the search path within a
+ A list of strings specifying the search path within a
 package. This attribute is not set on modules.
 
 - :attr:`__package__`
@@ -149,9 +154,9 @@
 for :attr:`__package__`.
 
 - :attr:`__loader__`
- Set to the loader used to load the module.
-
- See :pep:`302` for the exact definition for a loader.
+ The loader used to load the module.
+ (This is not set by the built-in import machinery,
+ but it should be set whenever a :term:`loader` is used.)
 
 
 .. class:: ResourceLoader
@@ -163,17 +168,18 @@
 .. method:: get_data(path)
 
 An abstract method to return the bytes for the data located at *path*.
- Loaders that have a file-like storage back-end can implement this
- abstract method to give direct access
+ Loaders that have a file-like storage back-end
+ that allows storing arbitrary data
+ can implement this abstract method to give direct access
 to the data stored. :exc:`IOError` is to be raised if the *path* cannot
 be found. The *path* is expected to be constructed using a module's
- :attr:`__path__` attribute or an item from :attr:`__path__`.
+ :attr:`__file__` attribute or an item from a package's :attr:`__path__`.
 
 
 .. class:: InspectLoader
 
 An abstract base class for a :term:`loader` which implements the optional
- :pep:`302` protocol for loaders which inspect modules.
+ :pep:`302` protocol for loaders that inspect modules.
 
 .. method:: get_code(fullname)
 
@@ -185,7 +191,7 @@
 .. method:: get_source(fullname)
 
 An abstract method to return the source of a module. It is returned as
- a string with universal newline support. Returns :keyword:`None` if no
+ a text string with universal newlines. Returns :keyword:`None` if no
 source is available (e.g. a built-in module). Raises :exc:`ImportError`
 if the loader cannot find the module specified.
 
@@ -224,14 +230,17 @@
 
 A concrete implementation of
 :meth:`importlib.abc.InspectLoader.get_code` that creates code objects
- from Python source code.
+ from Python source code, by requesting the source code (using
+ :meth:`source_path` and :meth:`get_data`), converting it to standard
+ newlines, and compiling it with the built-in :func:`compile` function.
 
 .. method:: get_source(fullname)
 
 A concrete implementation of
 :meth:`importlib.abc.InspectLoader.get_source`. Uses
 :meth:`importlib.abc.InspectLoader.get_data` and :meth:`source_path` to
- get the source code.
+ get the source code. It tries to guess the source encoding using
+ :func:`tokenize.detect_encoding`.
 
 
 .. class:: PyPycLoader
@@ -250,8 +259,9 @@
 .. method:: bytecode_path(fullname)
 
 An abstract method which returns the path to the bytecode for the
- specified module. :keyword:`None` is returned if there is no bytecode.
- :exc:`ImportError` is raised if the module is not found.
+ specified module, if it exists. It returns :keyword:`None`
+ if no bytecode exists (yet).
+ Raises :exc:`ImportError` if the module is not found.
 
 .. method:: write_bytecode(fullname, bytecode)
 
@@ -259,6 +269,7 @@
 use. If the bytecode is written, return :keyword:`True`. Return
 :keyword:`False` if the bytecode could not be written. This method
 should not be called if :data:`sys.dont_write_bytecode` is true.
+ The *bytecode* argument should be a bytes string or bytes array.
 
 
 :mod:`importlib.machinery` -- Importers and path hooks
@@ -328,16 +339,18 @@
 
 .. function:: module_for_loader(method)
 
- A :term:`decorator` for a :term:`loader` which handles selecting the proper
+ A :term:`decorator` for a :term:`loader` method,
+ to handle selecting the proper
 module object to load with. The decorated method is expected to have a call
 signature taking two positional arguments
 (e.g. ``load_module(self, module)``) for which the second argument
- will be the module object to be used by the loader. Note that the decorator
+ will be the module **object** to be used by the loader.
+ Note that the decorator
 will not work on static methods because of the assumption of two
 arguments.
 
- The decorated method will take in the name of the module to be loaded as
- expected for a :term:`loader`. If the module is not found in
+ The decorated method will take in the **name** of the module to be loaded
+ as expected for a :term:`loader`. If the module is not found in
 :data:`sys.modules` then a new one is constructed with its
 :attr:`__name__` attribute set. Otherwise the module found in
 :data:`sys.modules` will be passed into the method. If an
@@ -346,18 +359,17 @@
 module from being in left in :data:`sys.modules`. If the module was already
 in :data:`sys.modules` then it is left alone.
 
- Use of this decorator handles all the details of what module object a
+ Use of this decorator handles all the details of which module object a
 loader should initialize as specified by :pep:`302`.
 
-
 .. function:: set_loader(fxn)
 
- A :term:`decorator` for a :term:`loader` to set the :attr:`__loader__`
+ A :term:`decorator` for a :term:`loader` method,
+ to set the :attr:`__loader__`
 attribute on loaded modules. If the attribute is already set the decorator
 does nothing. It is assumed that the first positional argument to the
 wrapped method is what :attr:`__loader__` should be set to.
 
-
 .. function:: set_package(fxn)
 
 A :term:`decorator` for a :term:`loader` to set the :attr:`__package__`
@@ -365,3 +377,107 @@
 set and has a value other than :keyword:`None` it will not be changed.
 Note that the module returned by the loader is what has the attribute
 set on and not the module found in :data:`sys.modules`.
+
+ Reliance on this decorator is discouraged when it is possible to set
+ :attr:`__package__` before the execution of the code is possible. By
+ setting it before the code for the module is executed it allows the
+ attribute to be used at the global level of the module during
+ initialization.
+
+
+Example
+-------
+
+Below is an example meta path importer that uses a dict for back-end storage
+for source code. While not an optimal solution -- manipulations of
+:attr:`__path__` on packages does not influence import -- it does illustrate
+what little is required to implement an importer.
+
+.. testcode::
+
+ """An importer where source is stored in a dict."""
+ from importlib import abc
+
+
+ class DictImporter(abc.Finder, abc.PyLoader):
+
+ """A meta path importer that stores source code in a dict.
+
+ The keys are the module names -- packages must end in ``.__init__``.
+ The values must be something that can be passed to 'bytes'.
+
+ """
+
+ def __init__(self, memory):
+ """Store the dict."""
+ self.memory = memory
+
+ def contains(self, name):
+ """See if a module or package is in the dict."""
+ if name in self.memory:
+ return name
+ package_name = '{}.__init__'.format(name)
+ if package_name in self.memory:
+ return package_name
+ return False
+
+ __contains__ = contains # Convenience.
+
+ def find_module(self, fullname, path=None):
+ """Find the module in the dict."""
+ if fullname in self:
+ return self
+ return None
+
+ def source_path(self, fullname):
+ """Return the module name if the module is in the dict."""
+ if not fullname in self:
+ raise ImportError
+ return fullname
+
+ def get_data(self, path):
+ """Return the bytes for the source.
+
+ The value found in the dict is passed through 'bytes' before being
+ returned.
+
+ """
+ name = self.contains(path)
+ if not name:
+ raise IOError
+ return bytes(self.memory[name])
+
+ def is_package(self, fullname):
+ """Tell if module is a package based on whether the dict contains the
+ name with ``.__init__`` appended to it."""
+ if fullname not in self:
+ raise ImportError
+ if fullname in self.memory:
+ return False
+ # If name is in this importer but not as it is then it must end in
+ # ``__init__``.
+ else:
+ return True
+
+.. testcode::
+ :hide:
+
+ import importlib
+ import sys
+
+
+ # Build the dict; keys of name, value of __package__.
+ names = {'_top_level': '', '_pkg.__init__': '_pkg', '_pkg.mod': '_pkg'}
+ source = {name: "name = {!r}".format(name).encode() for name in names}
+
+ # Register the meta path importer.
+ importer = DictImporter(source)
+ sys.meta_path.append(importer)
+
+ # Sanity check.
+ for name in names:
+ module = importlib.import_module(name)
+ assert module.__name__ == name
+ assert getattr(module, 'name') == name
+ assert module.__loader__ is importer
+ assert module.__package__ == names[name]
Modified: python/branches/py3k-short-float-repr/Doc/library/io.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/io.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/io.rst	Sun Apr 5 01:04:14 2009
@@ -270,12 +270,18 @@
 interpreted relative to the position indicated by *whence*. Values for
 *whence* are:
 
- * ``0`` -- start of the stream (the default); *offset* should be zero or positive
- * ``1`` -- current stream position; *offset* may be negative
- * ``2`` -- end of the stream; *offset* is usually negative
+ * :data:`SEEK_SET` or ``0`` -- start of the stream (the default);
+ *offset* should be zero or positive
+ * :data:`SEEK_CUR` or ``1`` -- current stream position; *offset* may
+ be negative
+ * :data:`SEEK_END` or ``2`` -- end of the stream; *offset* is usually
+ negative
 
 Return the new absolute position.
 
+ .. versionadded:: 2.7
+ The ``SEEK_*`` constants
+
 .. method:: seekable()
 
 Return ``True`` if the stream supports random access. If ``False``,
Modified: python/branches/py3k-short-float-repr/Doc/library/mmap.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/mmap.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/mmap.rst	Sun Apr 5 01:04:14 2009
@@ -6,13 +6,13 @@
 :synopsis: Interface to memory-mapped files for Unix and Windows.
 
 
-Memory-mapped file objects behave like both strings and like file objects.
-Unlike normal string objects, however, these are mutable. You can use mmap
-objects in most places where strings are expected; for example, you can use
-the :mod:`re` module to search through a memory-mapped file. Since they're
-mutable, you can change a single character by doing ``obj[index] = 'a'``, or
-change a substring by assigning to a slice: ``obj[i1:i2] = '...'``. You can
-also read and write data starting at the current file position, and
+Memory-mapped file objects behave like both :class:`bytes` and like file
+objects. Unlike normal :class:`bytes` objects, however, these are mutable.
+You can use mmap objects in most places where :class:`bytes` are expected; for
+example, you can use the :mod:`re` module to search through a memory-mapped file.
+Since they're mutable, you can change a single byte by doing ``obj[index] = 97``,
+or change a subsequence by assigning to a slice: ``obj[i1:i2] = b'...'``.
+You can also read 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 :class:`mmap` constructor, which is
@@ -94,21 +94,21 @@
 
 # write a simple example file
 with open("hello.txt", "wb") as f:
- f.write("Hello Python!\n")
+ f.write(b"Hello Python!\n")
 
 with open("hello.txt", "r+b") 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!"
+ print(map.readline()) # prints b"Hello Python!\n"
 # read content via slice notation
- print(map[:5]) # prints "Hello"
+ print(map[:5]) # prints b"Hello"
 # update content using slice notation;
 # note that new content must have same size
- map[6:] = " world!\n"
+ map[6:] = b" world!\n"
 # ... and read again using standard file methods
 map.seek(0)
- print(map.readline()) # prints "Hello world!"
+ print(map.readline()) # prints b"Hello world!\n"
 # close the map
 map.close()
 
@@ -120,7 +120,7 @@
 import os
 
 map = mmap.mmap(-1, 13)
- map.write("Hello world!")
+ map.write(b"Hello world!")
 
 pid = os.fork()
 
@@ -140,10 +140,10 @@
 result in an exception being raised.
 
 
- .. method:: find(string[, start[, end]])
+ .. method:: find(sub[, start[, end]])
 
- Returns the lowest index in the object where the substring *string* is
- found, such that *string* is contained in the range [*start*, *end*].
+ Returns the lowest index in the object where the subsequence *sub* is
+ found, such that *sub* is contained in the range [*start*, *end*].
 Optional arguments *start* and *end* are interpreted as in slice notation.
 Returns ``-1`` on failure.
 
@@ -172,15 +172,15 @@
 
 .. method:: read(num)
 
- Return a string containing up to *num* bytes starting from the current
- file position; the file position is updated to point after the bytes that
- were returned.
+ Return a :class:`bytes` containing up to *num* bytes starting from the
+ current file position; the file position is updated to point after the
+ bytes that were returned.
 
 
 .. method:: read_byte()
 
- Returns a string of length 1 containing the character at the current file
- position, and advances the file position by 1.
+ Returns a byte at the current file position as an integer, and advances
+ the file position by 1.
 
 
 .. method:: readline()
@@ -196,10 +196,10 @@
 throw a :exc:`TypeError` exception.
 
 
- .. method:: rfind(string[, start[, end]])
+ .. method:: rfind(sub[, 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*].
+ Returns the highest index in the object where the subsequence *sub* is
+ found, such that *sub* is contained in the range [*start*, *end*].
 Optional arguments *start* and *end* are interpreted as in slice notation.
 Returns ``-1`` on failure.
 
@@ -223,9 +223,9 @@
 Returns the current position of the file pointer.
 
 
- .. method:: write(string)
+ .. method:: write(bytes)
 
- Write the bytes in *string* into memory at the current position of the
+ Write the bytes in *bytes* into memory at the current position of the
 file pointer; the file position is updated to point after the bytes that
 were written. If the mmap was created with :const:`ACCESS_READ`, then
 writing to it will throw a :exc:`TypeError` exception.
@@ -233,7 +233,7 @@
 
 .. method:: write_byte(byte)
 
- Write the single-character string *byte* into memory at the current
+ Write the the integer *byte* into memory at the current
 position of the file pointer; the file position is advanced by ``1``. If
 the mmap was created with :const:`ACCESS_READ`, then writing to it will
 throw a :exc:`TypeError` exception.
Modified: python/branches/py3k-short-float-repr/Doc/library/os.path.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/os.path.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/os.path.rst	Sun Apr 5 01:04:14 2009
@@ -189,7 +189,7 @@
 
 .. function:: normcase(path)
 
- Normalize the case of a pathname. On Unix, this returns the path unchanged; on
+ Normalize the case of a pathname. On Unix and MacOSX, this returns the path unchanged; on
 case-insensitive filesystems, it converts the path to lowercase. On Windows, it
 also converts forward slashes to backward slashes.
 
Modified: python/branches/py3k-short-float-repr/Doc/library/pickle.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/pickle.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/pickle.rst	Sun Apr 5 01:04:14 2009
@@ -14,6 +14,7 @@
 .. 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
 process whereby a Python object hierarchy is converted into a byte stream, and
@@ -265,11 +266,6 @@
 
 See :ref:`pickle-persistent` for details and examples of uses.
 
- .. method:: clear_memo()
-
- Deprecated. Use the :meth:`clear` method on :attr:`memo`, instead.
- Clear the pickler's memo, useful when reusing picklers.
-
 .. attribute:: fast
 
 Deprecated. Enable fast mode if set to a true value. The fast mode
@@ -280,26 +276,6 @@
 
 Use :func:`pickletools.optimize` if you need more compact pickles.
 
- .. attribute:: memo
-
- Dictionary holding previously pickled objects to allow shared or
- recursive objects to pickled by reference as opposed to by value.
-
-
-.. XXX Move these comments to somewhere more appropriate.
-
-It is possible to make multiple calls to the :meth:`dump` method of the same
-:class:`Pickler` instance. These must then be matched to the same number of
-calls to the :meth:`load` method of the corresponding :class:`Unpickler`
-instance. If the same object is pickled by multiple :meth:`dump` calls, the
-:meth:`load` will all yield references to the same object.
-
-Please note, this is intended for pickling multiple objects without intervening
-modifications to the objects or their parts. If you modify an object and then
-pickle it again using the same :class:`Pickler` instance, the object is not
-pickled again --- a reference to it is pickled and the :class:`Unpickler` will
-return the old value, not the modified one.
-
 
 .. class:: Unpickler(file, [\*, encoding="ASCII", errors="strict"])
 
@@ -593,7 +569,7 @@
 line = self.file.readline()
 if not line:
 return None
- if line.endswith("\n"):
+ if line.endswith('\n'):
 line = line[:-1]
 return "%i: %s" % (self.lineno, line)
 
@@ -707,25 +683,24 @@
 
 As our examples shows, you have to be careful with what you allow to be
 unpickled. Therefore if security is a concern, you may want to consider
-alternatives such as the marshalling API in :mod:`xmlrpc.client` or third-party
-solutions.
+alternatives such as the marshalling API in :mod:`xmlrpc.client` or
+third-party solutions.
 
 
 .. _pickle-example:
 
-Usage Examples
---------------
+Examples
+--------
 
-For the simplest code, use the :func:`dump` and :func:`load` functions. Note
-that a self-referencing list is pickled and restored correctly. ::
+For the simplest code, use the :func:`dump` and :func:`load` functions. ::
 
 import pickle
 
 # An arbitrary collection of objects supported by pickle.
 data = {
- 'a': [1, 2.0, 3, 4+6j],
- 'b': ("character string", b"byte string"),
- 'c': set([None, True, False])
+ 'a': [1, 2.0, 3, 4+6j],
+ 'b': ("character string", b"byte string"),
+ 'c': set([None, True, False])
 }
 
 with open('data.pickle', 'wb') as f:
@@ -743,11 +718,18 @@
 data = pickle.load(f)
 
 
+.. XXX: Add examples showing how to optimize pickles for size (like using
+.. pickletools.optimize() or the gzip module).
+
+
 .. seealso::
 
 Module :mod:`copyreg`
 Pickle interface constructor registration for extension types.
 
+ Module :mod:`pickletools`
+ Tools for working with and analyzing pickled data.
+
 Module :mod:`shelve`
 Indexed databases of objects; uses :mod:`pickle`.
 
Modified: python/branches/py3k-short-float-repr/Doc/library/pickletools.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/pickletools.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/pickletools.rst	Sun Apr 5 01:04:14 2009
@@ -3,16 +3,14 @@
 ===================================================
 
 .. module:: pickletools
- :synopsis: Contains extensive comments about the pickle protocols and pickle-machine
- opcodes, as well as some useful functions.
-
+ :synopsis: Contains extensive comments about the pickle protocols and pickle-machine opcodes, as well as some useful functions.
 
 This module contains various constants relating to the intimate details of the
-:mod:`pickle` module, some lengthy comments about the implementation, and a few
-useful functions for analyzing pickled data. The contents of this module are
-useful for Python core developers who are working on the :mod:`pickle` and
-:mod:`cPickle` implementations; ordinary users of the :mod:`pickle` module
-probably won't find the :mod:`pickletools` module relevant.
+:mod:`pickle` module, some lengthy comments about the implementation, and a
+few useful functions for analyzing pickled data. The contents of this module
+are useful for Python core developers who are working on the :mod:`pickle`;
+ordinary users of the :mod:`pickle` module probably won't find the
+:mod:`pickletools` module relevant.
 
 
 .. function:: dis(pickle[, out=None, memo=None, indentlevel=4])
@@ -24,7 +22,6 @@
 pickler. Successive levels, indicated by ``MARK`` opcodes in the stream, are
 indented by *indentlevel* spaces.
 
-
 .. function:: genops(pickle)
 
 Provides an :term:`iterator` over all of the opcodes in a pickle, returning a
Modified: python/branches/py3k-short-float-repr/Doc/library/random.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/random.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/random.rst	Sun Apr 5 01:04:14 2009
@@ -253,3 +253,7 @@
 Modeling and Computer Simulation Vol. 8, No. 1, January pp.3-30 1998.
 
 
+ `Complementary-Multiply-with-Carry recipe
+ <http://code.activestate.com/recipes/576707/>`_ for a compatible alternative
+ random number generator with a long period and comparatively simple update
+ operations.
Modified: python/branches/py3k-short-float-repr/Doc/library/shelve.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/shelve.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/shelve.rst	Sun Apr 5 01:04:14 2009
@@ -48,6 +48,12 @@
 disk, if feasible. This is called automatically when the shelf is closed with
 :meth:`close`.
 
+.. seealso::
+
+ `Persistent dictionary recipe <http://code.activestate.com/recipes/576642/>`_
+ with widely supported storage formats and having the speed of native
+ dictionaries.
+
 
 Restrictions
 ------------
Modified: python/branches/py3k-short-float-repr/Doc/library/time.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/time.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/time.rst	Sun Apr 5 01:04:14 2009
@@ -358,15 +358,17 @@
 
 .. function:: strptime(string[, format])
 
- Parse a string representing a time according to a format. The return value is
- a :class:`struct_time` as returned by :func:`gmtime` or :func:`localtime`.
+ Parse a string representing a time according to a format. The return value
+ is a :class:`struct_time` as returned by :func:`gmtime` or
+ :func:`localtime`.
 
 The *format* parameter uses the same directives as those used by
 :func:`strftime`; it defaults to ``"%a %b %d %H:%M:%S %Y"`` which matches the
- formatting returned by :func:`ctime`. If *string* cannot be parsed according to
- *format*, or if it has excess data after parsing, :exc:`ValueError` is raised.
- 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)``.
+ formatting returned by :func:`ctime`. If *string* cannot be parsed according
+ to *format*, or if it has excess data after parsing, :exc:`ValueError` is
+ raised. 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)``.
+ Both *string* and *format* must be strings.
 
 For example:
 
Modified: python/branches/py3k-short-float-repr/Doc/library/unittest.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/unittest.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/unittest.rst	Sun Apr 5 01:04:14 2009
@@ -1,4 +1,3 @@
-
 :mod:`unittest` --- Unit testing framework
 ==========================================
 
@@ -207,8 +206,8 @@
 widget = Widget('The widget')
 self.assertEqual(widget.size(), (50, 50), 'incorrect default size')
 
-Note that in order to test something, we use the one of the :meth:`assert\*` or
-:meth:`fail\*` methods provided by the :class:`TestCase` base class. If the
+Note that in order to test something, we use the one of the :meth:`assert\*`
+methods provided by the :class:`TestCase` base class. If the
 test fails, an exception will be raised, and :mod:`unittest` will identify the
 test case as a :dfn:`failure`. Any other exceptions will be treated as
 :dfn:`errors`. This helps you identify where the problem is: :dfn:`failures` are
@@ -238,13 +237,13 @@
 
 class DefaultWidgetSizeTestCase(SimpleWidgetTestCase):
 def runTest(self):
- self.failUnless(self.widget.size() == (50,50),
+ self.assertTrue(self.widget.size() == (50,50),
 'incorrect default size')
 
 class WidgetResizeTestCase(SimpleWidgetTestCase):
 def runTest(self):
 self.widget.resize(100,150)
- self.failUnless(self.widget.size() == (100,150),
+ self.assertTrue(self.widget.size() == (100,150),
 'wrong size after resize')
 
 If the :meth:`~TestCase.setUp` method raises an exception while the test is
@@ -286,12 +285,12 @@
 self.widget = None
 
 def testDefaultSize(self):
- self.failUnless(self.widget.size() == (50,50),
+ self.assertTrue(self.widget.size() == (50,50),
 'incorrect default size')
 
 def testResize(self):
 self.widget.resize(100,150)
- self.failUnless(self.widget.size() == (100,150),
+ self.assertTrue(self.widget.size() == (100,150),
 'wrong size after resize')
 
 Here we have not provided a :meth:`~TestCase.runTest` method, but have instead
@@ -605,23 +604,37 @@
 failures.
 
 
- .. method:: assert_(expr[, msg])
+ .. method:: assertTrue(expr[, msg])
+ assert_(expr[, msg])
 failUnless(expr[, msg])
- 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`.
 
+ .. deprecated:: 2.7
+ :meth:`failUnless`.
+
 
 .. method:: assertEqual(first, second[, msg])
 failUnlessEqual(first, second[, msg])
 
 Test that *first* and *second* are equal. If the values do not compare
 equal, the test will fail with the explanation given by *msg*, or
- :const:`None`. Note that using :meth:`failUnlessEqual` improves upon
- doing the comparison as the first parameter to :meth:`failUnless`: the
- default value for *msg* can be computed to include representations of both
- *first* and *second*.
+ :const:`None`. Note that using :meth:`assertEqual` improves upon
+ doing the comparison as the first parameter to :meth:`assertTrue`: the
+ default value for *msg* include representations of both *first* and
+ *second*.
+
+ In addition, if *first* and *second* are the exact same type and one of
+ list, tuple, dict, set, or frozenset or any type that a subclass
+ registers :meth:`addTypeEqualityFunc` the type specific equality function
+ will be called in order to generate a more useful default error message.
+
+ .. versionchanged:: 2.7
+ Added the automatic calling of type specific equality function.
+
+ .. deprecated:: 2.7
+ :meth:`failUnlessEqual`.
 
 
 .. method:: assertNotEqual(first, second[, msg])
@@ -629,11 +642,14 @@
 
 Test that *first* and *second* are not equal. If the values do compare
 equal, the test will fail with the explanation given by *msg*, or
- :const:`None`. Note that using :meth:`failIfEqual` improves upon doing
- the comparison as the first parameter to :meth:`failUnless` is that the
+ :const:`None`. Note that using :meth:`assertNotEqual` improves upon doing
+ the comparison as the first parameter to :meth:`assertTrue` is that the
 default value for *msg* can be computed to include representations of both
 *first* and *second*.
 
+ .. deprecated:: 2.7
+ :meth:`failIfEqual`.
+
 
 .. method:: assertAlmostEqual(first, second[, places[, msg]])
 failUnlessAlmostEqual(first, second[, places[, msg]])
@@ -647,6 +663,9 @@
 compare equal, the test will fail with the explanation given by *msg*, or
 :const:`None`.
 
+ .. deprecated:: 2.7
+ :meth:`failUnlessAlmostEqual`.
+
 
 .. method:: assertNotAlmostEqual(first, second[, places[, msg]])
 failIfAlmostEqual(first, second[, places[, msg]])
@@ -660,6 +679,128 @@
 compare equal, the test will fail with the explanation given by *msg*, or
 :const:`None`.
 
+ .. deprecated:: 2.7
+ :meth:`failIfAlmostEqual`.
+
+
+ .. method:: assertGreater(first, second, msg=None)
+ assertGreaterEqual(first, second, msg=None)
+ assertLess(first, second, msg=None)
+ assertLessEqual(first, second, msg=None)
+
+ Test that *first* is respectively >, >=, < or <= than *second* depending
+ on the method name. If not, the test will fail with the nice explanation
+ or with the explanation given by *msg*::
+
+ >>> self.assertGreaterEqual(3, 4)
+ AssertionError: "3" unexpectedly not greater than or equal to "4"
+
+ .. versionadded:: 2.7
+
+
+ .. method:: assertMultiLineEqual(self, first, second, msg=None)
+
+ Test that the multiline string *first* is equal to the string *second*.
+ When not equal a diff of the two strings highlighting the differences
+ will be included in the error message.
+
+ If specified *msg* will be used as the error message on failure.
+
+ .. versionadded:: 2.7
+
+
+ .. method:: assertRegexpMatches(text, regexp[, msg=None]):
+
+ Verifies that a *regexp* search matches *text*. Fails with an error
+ message including the pattern and the *text*. *regexp* may be
+ a regular expression object or a string containing a regular expression
+ suitable for use by :func:`re.search`.
+
+ .. versionadded:: 2.7
+
+
+ .. method:: assertIn(first, second, msg=None)
+ assertNotIn(first, second, msg=None)
+
+ Tests that *first* is or is not in *second* with a nice explanitory error
+ message as appropriate.
+
+ If specified *msg* will be used as the error message on failure.
+
+ .. versionadded:: 2.7
+
+
+ .. method:: assertSameElements(expected, actual, msg=None)
+
+ Test that sequence *expected* contains the same elements as *actual*.
+ When they don't an error message listing the differences between the
+ sequences will be generated.
+
+ If specified *msg* will be used as the error message on failure.
+
+ .. versionadded:: 2.7
+
+
+ .. method:: assertSetEqual(set1, set2, msg=None)
+
+ Tests that two sets are equal. If not, an error message is constructed
+ that lists the differences between the sets.
+
+ Fails if either of *set1* or *set2* does not have a :meth:`set.difference`
+ method.
+
+ If specified *msg* will be used as the error message on failure.
+
+ .. versionadded:: 2.7
+
+
+ .. method:: assertDictEqual(expected, actual, msg=None)
+
+ Test that two dictionaries are equal. If not, an error message is
+ constructed that shows the differences in the dictionaries.
+
+ If specified *msg* will be used as the error message on failure.
+
+ .. versionadded:: 2.7
+
+
+ .. method:: assertDictContainsSubset(expected, actual, msg=None)
+
+ Tests whether the key value pairs in dictionary *actual* are a
+ superset of those in *expected*. If not, an error message listing
+ the missing keys and mismatched values is generated.
+
+ If specified *msg* will be used as the error message on failure.
+
+ .. versionadded:: 2.7
+
+
+ .. method:: assertListEqual(list1, list2, msg=None)
+ assertTupleEqual(tuple1, tuple2, msg=None)
+
+ Tests that two lists or tuples are equal. If not an error message is
+ constructed that shows only the differences between the two. An error
+ is also raised if either of the parameters are of the wrong type.
+
+ If specified *msg* will be used as the error message on failure.
+
+ .. versionadded:: 2.7
+
+
+ .. method:: assertSequenceEqual(seq1, seq2, msg=None, seq_type=None)
+
+ Tests that two sequences are equal. If a *seq_type* is supplied, both
+ *seq1* and *seq2* must be instances of *seq_type* or a failure will
+ be raised. If the sequences are different an error message is
+ constructed that shows the difference between the two.
+
+ If specified *msg* will be used as the error message on failure.
+
+ This method is used to implement :meth:`assertListEqual` and
+ :meth:`assertTupleEqual`.
+
+ .. versionadded:: 2.7
+
 
 .. method:: assertRaises(exception[, callable, ...])
 failUnlessRaises(exception[, callable, ...])
@@ -680,14 +821,53 @@
 .. versionchanged:: 3.1
 Added the ability to use :meth:`assertRaises` as a context manager.
 
+ .. deprecated:: 2.7
+ :meth:`failUnlessRaises`.
+
+
+ .. method:: assertRaisesRegexp(exception, regexp[, callable, ...])
+
+ Like :meth:`assertRaises` but also tests that *regexp* matches
+ on the string representation of the raised exception. *regexp* may be
+ a regular expression object or a string containing a regular expression
+ suitable for use by :func:`re.search`. Examples::
+
+ self.assertRaisesRegexp(ValueError, 'invalid literal for.*XYZ$',
+ int, 'XYZ')
+
+ or::
 
- .. method:: failIf(expr[, msg])
- assertFalse(expr[, msg])
+ with self.assertRaisesRegexp(ValueError, 'literal'):
+ int('XYZ')
 
- The inverse of the :meth:`failUnless` method is the :meth:`failIf` method.
+ .. versionadded:: 2.7
+
+
+ .. method:: assertIsNone(expr[, msg])
+
+ This signals a test failure if *expr* is not None.
+
+ .. versionadded:: 2.7
+
+
+ .. method:: assertIsNotNone(expr[, msg])
+
+ The inverse of the :meth:`assertIsNone` method.
+ This signals a test failure if *expr* is None.
+
+ .. versionadded:: 2.7
+
+
+ .. method:: assertFalse(expr[, msg])
+ failIf(expr[, msg])
+
+ The inverse of the :meth:`assertTrue` method is the :meth:`assertFalse` method.
 This signals a test failure if *expr* is true, with *msg* or :const:`None`
 for the error message.
 
+ .. deprecated:: 2.7
+ :meth:`failIf`.
+
 
 .. method:: fail([msg])
 
@@ -703,6 +883,25 @@
 fair" with the framework. The initial value of this attribute is
 :exc:`AssertionError`.
 
+
+ .. attribute:: longMessage
+
+ If set to True then any explicit failure message you pass in to the
+ assert methods will be appended to the end of the normal failure message.
+ The normal messages contain useful information about the objects involved,
+ for example the message from assertEqual shows you the repr of the two
+ unequal objects. Setting this attribute to True allows you to have a
+ custom error message in addition to the normal one.
+
+ This attribute defaults to False, meaning that a custom message passed
+ to an assert method will silence the normal message.
+
+ The class setting can be overridden in individual tests by assigning an
+ instance attribute to True or False before calling the assert methods.
+
+ .. versionadded:: 2.7
+
+
 Testing frameworks can use the following methods to collect information on
 the test:
 
@@ -732,10 +931,34 @@
 
 .. method:: shortDescription()
 
- Returns a one-line description of the test, or :const:`None` if no
- description has been provided. The default implementation of this method
- returns the first line of the test method's docstring, if available, or
- :const:`None`.
+ Returns a description of the test, or :const:`None` if no description
+ has been provided. The default implementation of this method
+ returns the first line of the test method's docstring, if available,
+ along with the method name.
+
+ .. versionchanged:: 2.7
+
+ In earlier versions this only returned the first line of the test
+ method's docstring, if available or the :const:`None`. That led to
+ undesirable behavior of not printing the test name when someone was
+ thoughtful enough to write a docstring.
+
+
+ .. method:: addTypeEqualityFunc(typeobj, function)
+
+ Registers a type specific :meth:`assertEqual` equality checking
+ function to be called by :meth:`assertEqual` when both objects it has
+ been asked to compare are exactly *typeobj* (not subclasses).
+ *function* must take two positional arguments and a third msg=None
+ keyword argument just as :meth:`assertEqual` does. It must raise
+ self.failureException when inequality between the first two
+ parameters is detected.
+
+ One good use of custom equality checking functions for a type
+ is to raise self.failureException with an error message useful
+ for debugging the by explaining the inequalities in detail.
+
+ .. versionadded:: 2.7
 
 
 .. class:: FunctionTestCase(testFunc[, setUp[, tearDown[, description]]])
Modified: python/branches/py3k-short-float-repr/Doc/library/urllib.error.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/urllib.error.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/urllib.error.rst	Sun Apr 5 01:04:14 2009
@@ -3,7 +3,7 @@
 
 .. module:: urllib.error
 :synopsis: Exception classes raised by urllib.request.
-.. moduleauthor:: Jeremy Hylton <jhylton at users.sourceforge.net>
+.. moduleauthor:: Jeremy Hylton <jeremy at alum.mit.edu>
 .. sectionauthor:: Senthil Kumaran <orsenthil at gmail.com>
 
 
Modified: python/branches/py3k-short-float-repr/Doc/library/urllib.request.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/library/urllib.request.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/library/urllib.request.rst	Sun Apr 5 01:04:14 2009
@@ -3,7 +3,7 @@
 
 .. module:: urllib.request
 :synopsis: Next generation URL opening library.
-.. moduleauthor:: Jeremy Hylton <jhylton at users.sourceforge.net>
+.. moduleauthor:: Jeremy Hylton <jeremy at alum.mit.edu>
 .. sectionauthor:: Moshe Zadka <moshez at users.sourceforge.net>
 
 
@@ -16,26 +16,28 @@
 
 .. function:: urlopen(url[, data][, timeout])
 
- Open the URL *url*, which can be either a string or a :class:`Request` object.
+ Open the URL *url*, which can be either a string or a
+ :class:`Request` object.
 
- *data* may be a string specifying additional data to send to the server, or
- ``None`` if no such data is needed. Currently HTTP requests are the only ones
- that use *data*; the HTTP request will be a POST instead of a GET when the
- *data* parameter is provided. *data* should be a buffer in the standard
+ *data* may be a string specifying additional data to send to the
+ server, or ``None`` if no such data is needed. Currently HTTP
+ requests are the only ones that use *data*; the HTTP request will
+ be a POST instead of a GET when the *data* parameter is provided.
+ *data* should be a buffer in the standard
 :mimetype:`application/x-www-form-urlencoded` format. The
 :func:`urllib.parse.urlencode` function takes a mapping or sequence
 of 2-tuples and returns a string in this format.
 
- The optional *timeout* parameter specifies a timeout in seconds for blocking
- operations like the connection attempt (if not specified, the global default
- timeout setting will be used). This actually only works for HTTP, HTTPS,
- FTP and FTPS connections.
+ The optional *timeout* parameter specifies a timeout in seconds for
+ blocking operations like the connection attempt (if not specified,
+ the global default timeout setting will be used). This actually
+ only works for HTTP, HTTPS, FTP and FTPS connections.
 
 This function returns a file-like object with two additional methods from
 the :mod:`urllib.response` module
 
- * :meth:`geturl` --- return the URL of the resource retrieved, commonly used to
- determine if a redirect was followed
+ * :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, such as headers,
 in the form of an ``http.client.HTTPMessage`` instance (see `Quick
@@ -52,7 +54,6 @@
 Proxy handling, which was done by passing a dictionary parameter to
 ``urllib.urlopen``, can be obtained by using :class:`ProxyHandler` objects.
 
-
 .. function:: install_opener(opener)
 
 Install an :class:`OpenerDirector` instance as the default global opener.
@@ -167,37 +168,42 @@
 
 *url* should be a string containing a valid URL.
 
- *data* may be a string specifying additional data to send to the server, or
- ``None`` if no such data is needed. Currently HTTP requests are the only ones
- that use *data*; the HTTP request will be a POST instead of a GET when the
- *data* parameter is provided. *data* should be a buffer in the standard
+ *data* may be a string specifying additional data to send to the
+ server, or ``None`` if no such data is needed. Currently HTTP
+ requests are the only ones that use *data*; the HTTP request will
+ be a POST instead of a GET when the *data* parameter is provided.
+ *data* should be a buffer in the standard
 :mimetype:`application/x-www-form-urlencoded` format. The
 :func:`urllib.parse.urlencode` function takes a mapping or sequence
 of 2-tuples and 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. 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:`urllib`'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:
-
- *origin_req_host* should be the request-host of the origin transaction, as
- defined by :rfc:`2965`. It defaults to ``http.cookiejar.request_host(self)``.
- This is the host name or IP address of the original request that was
- initiated by the user. For example, if the request is for an image in an
- HTML document, this should be the request-host of the request for the page
+ *headers* should be a dictionary, and will be treated as if
+ :meth:`add_header` 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:`urllib`'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:
+
+ *origin_req_host* should be the request-host of the origin
+ transaction, as defined by :rfc:`2965`. It defaults to
+ ``http.cookiejar.request_host(self)``. This is the host name or IP
+ address of the original request that was initiated by the user.
+ For example, if the request is for an image in an HTML document,
+ this should be the request-host of the request for the page
 containing the image.
 
- *unverifiable* should indicate whether the request is unverifiable, as defined
- by RFC 2965. It defaults to False. An unverifiable request is one whose URL
- the user did not have the option to approve. For example, if the request is for
- an image in an HTML document, and the user had no option to approve the
- automatic fetching of the image, this should be true.
+ *unverifiable* should indicate whether the request is unverifiable,
+ as defined by RFC 2965. It defaults to False. An unverifiable
+ request is one whose URL the user did not have the option to
+ approve. For example, if the request is for an image in an HTML
+ document, and the user had no option to approve the automatic
+ fetching of the image, this should be true.
 
 .. class:: URLopener([proxies[, **x509]])
 
@@ -441,9 +447,41 @@
 Request Objects
 ---------------
 
-The following methods describe all of :class:`Request`'s public interface, and
-so all must be overridden in subclasses.
+The following methods describe :class:`Request`'s public interface,
+and so all may be overridden in subclasses. It also defines several
+public attributes that can be used by clients to inspect the parsed
+request.
+
+.. attribute:: Request.full_url
+
+ The original URL passed to the constructor.
+
+.. attribute:: Request.type
+
+ The URI scheme.
+
+.. attribute:: Request.host
+
+ The URI authority, typically a host, but may also contain a port
+ separated by a colon.
+
+.. attribute:: Request.origin_req_host
+
+ The original host for the request, without port.
+
+.. attribute:: Request.selector
+
+ The URI path. If the :class:`Request` uses a proxy, then selector
+ will be the full url that is passed to the proxy.
+
+.. attribute:: Request.data
+
+ The entity body for the request, or None if not specified.
+
+.. attribute:: Request.unverifiable
 
+ boolean, indicates whether the request is unverifiable as defined
+ by RFC 2965.
 
 .. method:: Request.add_data(data)
 
Modified: python/branches/py3k-short-float-repr/Doc/license.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/license.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/license.rst	Sun Apr 5 01:04:14 2009
@@ -31,7 +31,6 @@
 Source Definition). Historically, most, but not all, Python releases have also
 been GPL-compatible; the table below summarizes the various releases.
 
-<<<<<<< .working
 +----------------+--------------+------------+------------+-----------------+
 | Release | Derived from | Year | Owner | GPL compatible? |
 +================+==============+============+============+=================+
Modified: python/branches/py3k-short-float-repr/Doc/reference/datamodel.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/reference/datamodel.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/reference/datamodel.rst	Sun Apr 5 01:04:14 2009
@@ -1160,6 +1160,7 @@
 The return value must be a string object.
 
 
+.. _richcmpfuncs:
 .. method:: object.__lt__(self, other)
 object.__le__(self, other)
 object.__eq__(self, other)
Modified: python/branches/py3k-short-float-repr/Doc/whatsnew/3.1.rst
==============================================================================
--- python/branches/py3k-short-float-repr/Doc/whatsnew/3.1.rst	(original)
+++ python/branches/py3k-short-float-repr/Doc/whatsnew/3.1.rst	Sun Apr 5 01:04:14 2009
@@ -4,7 +4,7 @@
 
 .. XXX Add trademark info for Apple, Microsoft.
 
-:Author: No one so far
+:Author: Raymond Hettinger
 :Release: |release|
 :Date: |today|
 
@@ -66,6 +66,61 @@
 .. ======================================================================
 
 
+PEP 372: Ordered Dictionaries
+=============================
+
+Regular Python dictionaries iterate over key/value pairs in arbitrary order.
+Over the years, a number of authors have written alternative implementations
+that remember the order that the keys were originally inserted. Based on
+the experiences from those implementations, the :mod:`collections` module
+now has an :class:`OrderedDict` class.
+
+The OrderedDict API is substantially the same as regular dictionaries
+but will iterate over keys and values in a guaranteed order depending on
+when a key was first inserted. If a new entry overwrites an existing entry,
+the original insertion position is left unchanged. Deleting an entry and
+reinserting it will move it to the end.
+
+The standard library now supports use of ordered dictionaries in several
+modules. The :mod:`ConfigParser` module uses them by default. This lets
+configuration files be read, modified, and then written back in their original
+order. The :mod:`collections` module's :meth:`namedtuple._asdict` method now
+returns an ordered dictionary with the values appearing in the same order as
+the underlying tuple indicies. The :mod:`json` module is being built-out with
+an *object_pairs_hook* to allow OrderedDicts to be built by the decoder.
+Support was also added for third-party tools like PyYAML.
+
+.. seealso::
+
+ :pep:`372` - Ordered Dictionaries
+ PEP written by Armin Ronacher and Raymond Hettinger. Implementation
+ written by Raymond Hettinger.
+
+PEP 378: Format Specifier for Thousands Separator
+=================================================
+
+The builtin :func:`format` function and the :meth:`str.format` method use
+a mini-language that now includes a simple, non-locale aware way to format
+a number with a thousands separator. That provides a way to humanize a
+program's output, improving its professional appearance and readability::
+
+ >>> format(Decimal('1234567.89'), ',f')
+ '1,234,567.89'
+
+The currently supported types are :class:`int` and :class:`decimal.Decimal`.
+Support for :class:`float` is expected before the beta release.
+Discussions are underway about how to specify alternative separators
+like dots, spaces, apostrophes, or underscores. Locale-aware applications
+should use the existing *n* format specifier which already has some support
+for thousands separators.
+
+.. seealso::
+
+ :pep:`378` - Format Specifier for Thousands Separator
+ PEP written by Raymond Hettinger; implemented by Eric Smith and
+ Mark Dickinson.
+
+
 Other Language Changes
 ======================
 
@@ -85,31 +140,117 @@
 >>> (n+1).bit_length()
 124
 
- (Contributed by Fredrik Johansson and Victor Stinner; :issue:`3439`.)
+ (Contributed by Fredrik Johansson, Victor Stinner, Raymond Hettinger,
+ and Mark Dickinson; :issue:`3439`.)
 
-* Integers are now stored internally either in base 2**15 or in base
- 2**30, the base being determined at build time. Previously, they
- were always stored in base 2**15. Using base 2**30 gives
- significant performance improvements on 64-bit machines, but
- benchmark results on 32-bit machines have been mixed. Therefore,
- the default is to use base 2**30 on 64-bit machines and base 2**15
- on 32-bit machines; on Unix, there's a new configure option
- --enable-big-digits that can be used to override this default.
+* Added a :class:`collections.Counter` class to support convenient
+ counting of unique items in a sequence or iterable::
 
- Apart from the performance improvements this change should be
- invisible to end users, with one exception: for testing and
- debugging purposes there's a new structseq ``sys.int_info`` that
- provides information about the internal format, giving the number of
- bits per digit and the size in bytes of the C type used to store
- each digit::
+ >>> Counter(['red', 'blue', 'red', 'green', 'blue', 'blue'])
+ Counter({'blue': 3, 'red': 2, 'green': 1})
 
- >>> import sys
- >>> sys.int_info
- sys.int_info(bits_per_digit=30, sizeof_digit=4)
+ (Contributed by Raymond Hettinger; :issue:`1696199`.)
 
+* Add a new module, :mod:`ttk` for access to the Tk themed widget set. The
+ basic idea of ttk is to separate, to the extent possible, the code
+ implementing a widget's behavior from the code implementing its appearance.
 
- (Contributed by Mark Dickinson; :issue:`4258`.)
+ (Contributed by Kevin Walzer and Guilherme Polo; :issue:`2618` and
+ :issue:`2983`.)
+
+* The :class:`gzip.GzipFile` and :class:`bz2.BZ2File` classs now support
+ the context manager protocol.
+
+ (Contributed by Jacques Frechet; :issue:`4272`.)
+
+* The :mod:`Decimal` module now supports two new methods to create a
+ decimal object that from a binary :class:`float`. The conversion is
+ exact but can sometimes be surprising::
+
+ >>> Decimal.from_float(1.1)
+ Decimal('1.100000000000000088817841970012523233890533447265625')
+
+ The long decimal result shows the actual binary fraction being
+ stored for *1.1*. The fraction has many digits because *1.1* cannot
+ be exactly represented in binary.
+
+ (Contributed by Raymond Hettinger and Mark Dickinson.)
+
+* The fields in :func:`format` strings can now be automatically
+ numbered::
+
+ >>> 'Sir {} of {}'.format('Gallahad', 'Camelot')
+ 'Sir Gallahad of Camelot'
+
+ Formerly, the string would have required numbered fields such as:
+ ``'Sir {0} of {1}'``.
+
+ (Contributed by Eric Smith; :issue:`5237`.)
+
+* The :mod:`itertools` module grew two new functions. The
+ :func:`itertools.combinations_with_replacement` function is one of
+ four for generating combinatorics including permutations and Cartesian
+ products. The :func:`itertools.compress` function mimics its namesake
+ from APL. Also, the existing :func:`itertools.count` function now has
+ an optional *step* argument and can accept any type of counting
+ sequence including :class:`fractions.Fraction` and
+ :class:`decimal.Decimal`.
+
+ (Contributed by Raymond Hettinger.)
+
+* :func:`collections.namedtuple` now supports a keyword argument
+ *rename* which lets invalid fieldnames be automatically converted to
+ positional names in the form _0, _1, etc. This is useful when
+ the field names are being created by an external source such as a
+ CSV header, SQL field list, or user input.
+
+ (Contributed by Raymond Hettinger; :issue:`1818`.)
+
+* ``round`(x, n)`` now returns an integer if *x* is an integer.
+ Previously it returned a float.
+
+ (Contributed by Mark Dickinson; :issue:`4707`.)
+
+* The :func:`re.sub`, :func:`re.subn` and :func:`re.split` functions now
+ accept a flags parameter.
+
+ (Contributed by Gregory Smith.)
 
+* The :mod:`runpy` module which supports the ``-m`` command line switch
+ now supports the execution of packages by looking for and executing
+ a ``__main__`` submodule when a package name is supplied.
+
+ (Contributed by Andi Vajda; :issue:`4195`.)
+
+* The :mod:`pdb` module can now access and display source code loaded via
+ :mod:`zipimport` (or any other conformant :pep:`302` loader).
+
+ (Contributed by Alexander Belopolsky; :issue:`4201`.)
+
+* :class:`functools.partial` objects can now be pickled.
+
+ (Suggested by Antoine Pitrou and Jesse Noller. Implemented by
+ Jack Diedrich; :issue:`5228`.)
+
+* Add :mod:`pydoc` help topics for symbols so that ``help('@')``
+ works as expected in the interactive environment.
+
+ (Contributed by David Laban; :issue:`4739`.)
+
+* The :mod:`unittest` module now supports skipping individual tests or classes
+ of tests. And it supports marking a test as a expected failure, a test that
+ is known to be broken, but shouldn't be counted as a failure on a
+ TestResult.
+
+ (Contributed by Benjamin Peterson.)
+
+* A new module, :mod:`importlib` was added. It provides a complete, portable,
+ pure Python reference implementation of the *import* statement and its
+ counterpart, the :func:`__import__` function. It represents a substantial
+ step forward in documenting and defining the actions that take place during
+ imports.
+
+ (Contributed by Brett Cannon.)
 
 .. ======================================================================
 
@@ -128,11 +269,52 @@
 
 (Contributed by Amaury Forgeot d'Arc and Antoine Pitrou.)
 
-* A new configure flag, ``--with-computed-gotos``, enables a faster opcode
- dispatch mechanism on compilers which support it. Speedups of up to 20%
- have been observed, depending on the system and compiler.
+* Added a heuristic so that tuples and dicts containing only untrackable objects
+ are not tracked by the garbage collector. This can reduce the size of
+ collections and therefore the garbage collection overhead on long-running
+ programs, depending on their particular use of datatypes.
+
+ (Contributed by Antoine Pitrou, :issue:`4688`.)
+
+* Enabling a configure option named ``--with-computed-gotos``
+ on compilers that support it (notably: gcc, SunPro, icc), the bytecode
+ evaluation loop is compiled with a new dispatch mechanism which gives
+ speedups of up to 20%, depending on the system, the compiler, and
+ the benchmark.
+
+ (Contributed by Antoine Pitrou along with a number of other participants,
+ :issue:`4753`).
+
+* The decoding of UTF-8, UTF-16 and LATIN-1 is now two to four times
+ faster.
+
+ (Contributed by Antoine Pitrou and Amaury Forgeot d'Arc, :issue:`4868`.)
 
- (Contributed by Antoine Pitrou, :issue:`4753`.)
+* The :mod:`json` module is getting a C extension to substantially improve
+ its performance. The code is expected to be added in-time for the beta
+ release.
 
+ (Contributed by Bob Ippolito.)
+
+* Integers are now stored internally either in base 2**15 or in base
+ 2**30, the base being determined at build time. Previously, they
+ were always stored in base 2**15. Using base 2**30 gives
+ significant performance improvements on 64-bit machines, but
+ benchmark results on 32-bit machines have been mixed. Therefore,
+ the default is to use base 2**30 on 64-bit machines and base 2**15
+ on 32-bit machines; on Unix, there's a new configure option
+ ``--enable-big-digits`` that can be used to override this default.
+
+ Apart from the performance improvements this change should be invisible to
+ end users, with one exception: for testing and debugging purposes there's a
+ new :class:`structseq` ``sys.int_info`` that provides information about the
+ internal format, giving the number of bits per digit and the size in bytes
+ of the C type used to store each digit::
+
+ >>> import sys
+ >>> sys.int_info
+ sys.int_info(bits_per_digit=30, sizeof_digit=4)
+
+ (Contributed by Mark Dickinson; :issue:`4258`.)
 
 .. ======================================================================
Modified: python/branches/py3k-short-float-repr/Grammar/Grammar
==============================================================================
--- python/branches/py3k-short-float-repr/Grammar/Grammar	(original)
+++ python/branches/py3k-short-float-repr/Grammar/Grammar	Sun Apr 5 01:04:14 2009
@@ -87,7 +87,7 @@
 and_test: not_test ('and' not_test)*
 not_test: 'not' not_test | comparison
 comparison: star_expr (comp_op star_expr)*
-comp_op: '<'|'>'|'=='|'>='|'<='|'!='|'in'|'not' 'in'|'is'|'is' 'not'
+comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
 star_expr: ['*'] expr
 expr: xor_expr ('|' xor_expr)*
 xor_expr: and_expr ('^' and_expr)*
Modified: python/branches/py3k-short-float-repr/Include/bytesobject.h
==============================================================================
--- python/branches/py3k-short-float-repr/Include/bytesobject.h	(original)
+++ python/branches/py3k-short-float-repr/Include/bytesobject.h	Sun Apr 5 01:04:14 2009
@@ -91,13 +91,25 @@
 into the string pointed to by buffer. For the argument descriptions,
 see Objects/stringlib/localeutil.h */
 
-PyAPI_FUNC(int) _PyBytes_InsertThousandsGrouping(char *buffer,
+PyAPI_FUNC(int) _PyBytes_InsertThousandsGroupingLocale(char *buffer,
 						 Py_ssize_t n_buffer,
 						 Py_ssize_t n_digits,
 						 Py_ssize_t buf_size,
 						 Py_ssize_t *count,
 						 int append_zero_char);
 
+/* Using explicit passed-in values, insert the thousands grouping
+ into the string pointed to by buffer. For the argument descriptions,
+ see Objects/stringlib/localeutil.h */
+PyAPI_FUNC(int) _PyBytes_InsertThousandsGrouping(char *buffer,
+						 Py_ssize_t n_buffer,
+						 Py_ssize_t n_digits,
+						 Py_ssize_t buf_size,
+						 Py_ssize_t *count,
+ int append_zero_char,
+ const char *grouping,
+ const char *thousands_sep);
+
 /* Flags used by string formatting */
 #define F_LJUST (1<<0)
 #define F_SIGN	(1<<1)
Modified: python/branches/py3k-short-float-repr/Include/code.h
==============================================================================
--- python/branches/py3k-short-float-repr/Include/code.h	(original)
+++ python/branches/py3k-short-float-repr/Include/code.h	Sun Apr 5 01:04:14 2009
@@ -52,10 +52,12 @@
 #define CO_FUTURE_UNICODE_LITERALS 0x20000
 #endif
 
+#define CO_FUTURE_BARRY_AS_BDFL 0x40000
+
 /* This should be defined if a future statement modifies the syntax.
 For example, when a keyword is added.
 */
-/* #define PY_PARSER_REQUIRES_FUTURE_KEYWORD */
+#define PY_PARSER_REQUIRES_FUTURE_KEYWORD
 
 #define CO_MAXBLOCKS 20 /* Max static block nesting within a function */
 
Modified: python/branches/py3k-short-float-repr/Include/compile.h
==============================================================================
--- python/branches/py3k-short-float-repr/Include/compile.h	(original)
+++ python/branches/py3k-short-float-repr/Include/compile.h	Sun Apr 5 01:04:14 2009
@@ -26,6 +26,7 @@
 #define FUTURE_WITH_STATEMENT "with_statement"
 #define FUTURE_PRINT_FUNCTION "print_function"
 #define FUTURE_UNICODE_LITERALS "unicode_literals"
+#define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL"
 
 struct _mod; /* Declare the existence of this type */
 PyAPI_FUNC(PyCodeObject *) PyAST_Compile(struct _mod *, const char *,
Modified: python/branches/py3k-short-float-repr/Include/import.h
==============================================================================
--- python/branches/py3k-short-float-repr/Include/import.h	(original)
+++ python/branches/py3k-short-float-repr/Include/import.h	Sun Apr 5 01:04:14 2009
@@ -43,7 +43,7 @@
 PyAPI_DATA(PyTypeObject) PyNullImporter_Type;
 PyAPI_DATA(struct _inittab *) PyImport_Inittab;
 
-PyAPI_FUNC(int) PyImport_AppendInittab(char *name, PyObject* (*initfunc)(void));
+PyAPI_FUNC(int) PyImport_AppendInittab(const char *name, PyObject* (*initfunc)(void));
 PyAPI_FUNC(int) PyImport_ExtendInittab(struct _inittab *newtab);
 
 struct _frozen {
Modified: python/branches/py3k-short-float-repr/Include/parsetok.h
==============================================================================
--- python/branches/py3k-short-float-repr/Include/parsetok.h	(original)
+++ python/branches/py3k-short-float-repr/Include/parsetok.h	Sun Apr 5 01:04:14 2009
@@ -30,6 +30,7 @@
 #endif
 
 #define PyPARSE_IGNORE_COOKIE 0x0010
+#define PyPARSE_BARRY_AS_BDFL 0x0020
 
 PyAPI_FUNC(node *) PyParser_ParseString(const char *, grammar *, int,
 perrdetail *);
Modified: python/branches/py3k-short-float-repr/Include/patchlevel.h
==============================================================================
--- python/branches/py3k-short-float-repr/Include/patchlevel.h	(original)
+++ python/branches/py3k-short-float-repr/Include/patchlevel.h	Sun Apr 5 01:04:14 2009
@@ -20,10 +20,10 @@
 #define PY_MINOR_VERSION	1
 #define PY_MICRO_VERSION	0
 #define PY_RELEASE_LEVEL	PY_RELEASE_LEVEL_ALPHA
-#define PY_RELEASE_SERIAL	1
+#define PY_RELEASE_SERIAL	2
 
 /* Version as a string */
-#define PY_VERSION 	"3.1a1+"
+#define PY_VERSION 	"3.1a2"
 /*--end constants--*/
 
 /* Subversion Revision number of this file (not of the repository) */
Modified: python/branches/py3k-short-float-repr/Include/pythonrun.h
==============================================================================
--- python/branches/py3k-short-float-repr/Include/pythonrun.h	(original)
+++ python/branches/py3k-short-float-repr/Include/pythonrun.h	Sun Apr 5 01:04:14 2009
@@ -7,7 +7,7 @@
 extern "C" {
 #endif
 
-#define PyCF_MASK 0
+#define PyCF_MASK CO_FUTURE_BARRY_AS_BDFL
 #define PyCF_MASK_OBSOLETE 0
 #define PyCF_SOURCE_IS_UTF8 0x0100
 #define PyCF_DONT_IMPLY_DEDENT 0x0200
Modified: python/branches/py3k-short-float-repr/Include/unicodeobject.h
==============================================================================
--- python/branches/py3k-short-float-repr/Include/unicodeobject.h	(original)
+++ python/branches/py3k-short-float-repr/Include/unicodeobject.h	Sun Apr 5 01:04:14 2009
@@ -1482,13 +1482,24 @@
 into the string pointed to by buffer. For the argument descriptions,
 see Objects/stringlib/localeutil.h */
 
-PyAPI_FUNC(int) _PyUnicode_InsertThousandsGrouping(Py_UNICODE *buffer,
+PyAPI_FUNC(int) _PyUnicode_InsertThousandsGroupingLocale(Py_UNICODE *buffer,
 						 Py_ssize_t n_buffer,
 						 Py_ssize_t n_digits,
 						 Py_ssize_t buf_size,
 						 Py_ssize_t *count,
 						 int append_zero_char);
 
+/* Using explicit passed-in values, insert the thousands grouping
+ into the string pointed to by buffer. For the argument descriptions,
+ see Objects/stringlib/localeutil.h */
+PyAPI_FUNC(int) _PyUnicode_InsertThousandsGrouping(Py_UNICODE *buffer,
+						 Py_ssize_t n_buffer,
+						 Py_ssize_t n_digits,
+						 Py_ssize_t buf_size,
+						 Py_ssize_t *count,
+ int append_zero_char,
+ const char *grouping,
+ const char *thousands_sep);
 /* === Characters Type APIs =============================================== */
 
 /* Helper array used by Py_UNICODE_ISSPACE(). */
Modified: python/branches/py3k-short-float-repr/Lib/__future__.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/__future__.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/__future__.py	Sun Apr 5 01:04:14 2009
@@ -55,6 +55,7 @@
 "with_statement",
 "print_function",
 "unicode_literals",
+ "barry_as_FLUFL",
 ]
 
 __all__ = ["all_feature_names"] + all_feature_names
@@ -70,6 +71,7 @@
 CO_FUTURE_WITH_STATEMENT = 0x8000 # with statement
 CO_FUTURE_PRINT_FUNCTION = 0x10000 # print function
 CO_FUTURE_UNICODE_LITERALS = 0x20000 # unicode string literals
+CO_FUTURE_BARRY_AS_BDFL = 0x40000
 
 class _Feature:
 def __init__(self, optionalRelease, mandatoryRelease, compiler_flag):
@@ -126,3 +128,7 @@
 unicode_literals = _Feature((2, 6, 0, "alpha", 2),
 (3, 0, 0, "alpha", 0),
 CO_FUTURE_UNICODE_LITERALS)
+
+barry_as_FLUFL = _Feature((3, 1, 0, "alpha", 2),
+ (3, 9, 0, "alpha", 0),
+ CO_FUTURE_BARRY_AS_BDFL)
Modified: python/branches/py3k-short-float-repr/Lib/_abcoll.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/_abcoll.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/_abcoll.py	Sun Apr 5 01:04:14 2009
@@ -320,10 +320,9 @@
 self.add(value)
 return self
 
- def __iand__(self, c: Container):
- for value in self:
- if value not in c:
- self.discard(value)
+ def __iand__(self, it: Iterable):
+ for value in (self - it):
+ self.discard(value)
 return self
 
 def __ixor__(self, it: Iterable):
Modified: python/branches/py3k-short-float-repr/Lib/_pyio.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/_pyio.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/_pyio.py	Sun Apr 5 01:04:14 2009
@@ -14,6 +14,7 @@
 
 import io
 from io import __all__
+from io import SEEK_SET, SEEK_CUR, SEEK_END
 
 # open() uses st_blksize whenever we can
 DEFAULT_BUFFER_SIZE = 8 * 1024 # bytes
@@ -1696,6 +1697,7 @@
 return cookie
 
 def read(self, n=None):
+ self._checkReadable()
 if n is None:
 n = -1
 decoder = self._decoder or self._get_decoder()
@@ -1827,6 +1829,10 @@
 encoding="utf-8",
 errors="strict",
 newline=newline)
+ # Issue #5645: make universal newlines semantics the same as in the
+ # C version, even under Windows.
+ if newline is None:
+ self._writetranslate = False
 if initial_value:
 if not isinstance(initial_value, str):
 initial_value = str(initial_value)
Modified: python/branches/py3k-short-float-repr/Lib/_strptime.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/_strptime.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/_strptime.py	Sun Apr 5 01:04:14 2009
@@ -262,7 +262,7 @@
 
 def compile(self, format):
 """Return a compiled re object for the format string."""
- return re_compile(self.pattern(format), IGNORECASE | ASCII)
+ return re_compile(self.pattern(format), IGNORECASE)
 
 _cache_lock = _thread_allocate_lock()
 # DO NOT modify _TimeRE_cache or _regex_cache without acquiring the cache lock
@@ -294,8 +294,15 @@
 
 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."""
+
+ for index, arg in enumerate([data_string, format]):
+ if not isinstance(arg, str):
+ msg = "strptime() argument {} must be str, not {}"
+ raise TypeError(msg.format(index, type(arg)))
+
 global _TimeRE_cache, _regex_cache
 with _cache_lock:
+
 if _getlang() != _TimeRE_cache.locale_time.lang:
 _TimeRE_cache = TimeRE()
 _regex_cache.clear()
Modified: python/branches/py3k-short-float-repr/Lib/bisect.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/bisect.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/bisect.py	Sun Apr 5 01:04:14 2009
@@ -87,6 +87,6 @@
 
 # Overwrite above definitions with a fast C implementation
 try:
- from _bisect import bisect_right, bisect_left, insort_left, insort_right, insort, bisect
+ from _bisect import *
 except ImportError:
 pass
Modified: python/branches/py3k-short-float-repr/Lib/cgitb.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/cgitb.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/cgitb.py	Sun Apr 5 01:04:14 2009
@@ -19,13 +19,19 @@
 for you, call cgitb.handler(). The optional argument to handler() is a
 3-item tuple (etype, evalue, etb) just like the value of sys.exc_info().
 The default handler displays output as HTML.
-"""
-
-__author__ = 'Ka-Ping Yee'
-
-__version__ = '$Revision$'
 
+"""
+import inspect
+import keyword
+import linecache
+import os
+import pydoc
 import sys
+import tempfile
+import time
+import tokenize
+import traceback
+import types
 
 def reset():
 """Return a string that resets the CGI and browser to a known state."""
@@ -74,7 +80,6 @@
 
 def scanvars(reader, frame, locals):
 """Scan one logical line of Python and look up values of variables used."""
- import tokenize, keyword
 vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__
 for ttype, token, start, end, line in tokenize.generate_tokens(reader):
 if ttype == tokenize.NEWLINE: break
@@ -96,8 +101,6 @@
 
 def html(einfo, context=5):
 """Return a nice HTML document describing a given traceback."""
- import os, time, traceback, linecache, inspect, pydoc
-
 etype, evalue, etb = einfo
 if isinstance(etype, type):
 etype = etype.__name__
@@ -173,7 +176,6 @@
 value = pydoc.html.repr(getattr(evalue, name))
 exception.append('\n<br>%s%s&nbsp;=\n%s' % (indent, name, value))
 
- import traceback
 return head + ''.join(frames) + ''.join(exception) + '''
 
 
@@ -188,8 +190,6 @@
 
 def text(einfo, context=5):
 """Return a plain text document describing a given traceback."""
- import os, time, traceback, linecache, inspect, pydoc
-
 etype, evalue, etb = einfo
 if isinstance(etype, type):
 etype = etype.__name__
@@ -245,7 +245,6 @@
 value = pydoc.text.repr(getattr(evalue, name))
 exception.append('\n%s%s = %s' % (" "*4, name, value))
 
- import traceback
 return head + ''.join(frames) + ''.join(exception) + '''
 
 The above is a description of an error in a Python program. Here is
@@ -278,7 +277,6 @@
 try:
 doc = formatter(info, self.context)
 except: # just in case something goes wrong
- import traceback
 doc = ''.join(traceback.format_exception(*info))
 plain = True
 
@@ -292,7 +290,6 @@
 self.file.write('<p>A problem occurred in a Python script.\n')
 
 if self.logdir is not None:
- import os, tempfile
 suffix = ['.txt', '.html'][self.format=="html"]
 (fd, path) = tempfile.mkstemp(suffix=suffix, dir=self.logdir)
 try:
Modified: python/branches/py3k-short-float-repr/Lib/collections.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/collections.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/collections.py	Sun Apr 5 01:04:14 2009
@@ -132,6 +132,9 @@
 all(p==q for p, q in zip(self.items(), other.items()))
 return dict.__eq__(self, other)
 
+ def __ne__(self, other):
+ return not self == other
+
 
 
 ################################################################################
@@ -174,7 +177,7 @@
 if (not all(c.isalnum() or c=='_' for c in name) or _iskeyword(name)
 or not name or name[0].isdigit() or name.startswith('_')
 or name in seen):
- names[i] = '_%d' % (i+1)
+ names[i] = '_%d' % i
 seen.add(name)
 field_names = tuple(names)
 for name in (typename,) + field_names:
@@ -461,10 +464,10 @@
 '''
 if not isinstance(other, Counter):
 return NotImplemented
- _max = max
 result = Counter()
 for elem in set(self) | set(other):
- newcount = _max(self[elem], other[elem])
+ p, q = self[elem], other[elem]
+ newcount = q if p < q else p
 if newcount > 0:
 result[elem] = newcount
 return result
@@ -478,12 +481,12 @@
 '''
 if not isinstance(other, Counter):
 return NotImplemented
- _min = min
 result = Counter()
 if len(self) < len(other):
 self, other = other, self
 for elem in filter(self.__contains__, other):
- newcount = _min(self[elem], other[elem])
+ p, q = self[elem], other[elem]
+ newcount = p if p < q else q
 if newcount > 0:
 result[elem] = newcount
 return result
Modified: python/branches/py3k-short-float-repr/Lib/distutils/__init__.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/__init__.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/__init__.py	Sun Apr 5 01:04:14 2009
@@ -15,5 +15,5 @@
 # Updated automatically by the Python release process.
 #
 #--start constants--
-__version__ = "3.1a1"
+__version__ = "3.1a2"
 #--end constants--
Modified: python/branches/py3k-short-float-repr/Lib/distutils/cmd.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/cmd.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/cmd.py	Sun Apr 5 01:04:14 2009
@@ -333,7 +333,7 @@
 # -- External world manipulation -----------------------------------
 
 def warn(self, msg):
- sys.stderr.write("warning: %s: %s\n" % (self.get_command_name(), msg))
+ log.warn("warning: %s: %s\n" % (self.get_command_name(), msg))
 
 def execute(self, func, args, msg=None, level=1):
 util.execute(func, args, msg, dry_run=self.dry_run)
Modified: python/branches/py3k-short-float-repr/Lib/distutils/command/build_ext.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/command/build_ext.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/command/build_ext.py	Sun Apr 5 01:04:14 2009
@@ -455,7 +455,13 @@
 self.check_extensions_list(self.extensions)
 
 for ext in self.extensions:
- self.build_extension(ext)
+ try:
+ self.build_extension(ext)
+ except (CCompilerError, DistutilsError, CompileError) as e:
+ if not ext.optional:
+ raise
+ self.warn('building extension "%s" failed: %s' %
+ (ext.name, e))
 
 def build_extension(self, ext):
 sources = ext.sources
Modified: python/branches/py3k-short-float-repr/Lib/distutils/command/install_data.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/command/install_data.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/command/install_data.py	Sun Apr 5 01:04:14 2009
@@ -31,7 +31,6 @@
 self.outfiles = []
 self.root = None
 self.force = 0
-
 self.data_files = self.distribution.data_files
 self.warn_dir = 1
 
Modified: python/branches/py3k-short-float-repr/Lib/distutils/command/install_headers.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/command/install_headers.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/command/install_headers.py	Sun Apr 5 01:04:14 2009
@@ -8,6 +8,7 @@
 from distutils.core import Command
 
 
+# XXX force is never used
 class install_headers(Command):
 
 description = "install C/C++ header files"
Modified: python/branches/py3k-short-float-repr/Lib/distutils/command/register.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/command/register.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/command/register.py	Sun Apr 5 01:04:14 2009
@@ -92,15 +92,14 @@
 '''
 url = self.repository+'?:action=list_classifiers'
 response = urllib.request.urlopen(url)
- print(response.read())
+ log.info(response.read())
 
 def verify_metadata(self):
 ''' Send the metadata to the package index server to be checked.
 '''
 # send the info to the server and report the result
 (code, result) = self.post_to_server(self.build_post_data('verify'))
- print('Server response (%s): %s'%(code, result))
-
+ log.info('Server response (%s): %s' % (code, result))
 
 def send_metadata(self):
 ''' Send the metadata to the package index server.
@@ -211,17 +210,18 @@
 data['email'] = input(' EMail: ')
 code, result = self.post_to_server(data)
 if code != 200:
- print('Server response (%s): %s'%(code, result))
+ log.info('Server response (%s): %s' % (code, result))
 else:
- print('You will receive an email shortly.')
- print('Follow the instructions in it to complete registration.')
+ log.info('You will receive an email shortly.')
+ log.info(('Follow the instructions in it to '
+ 'complete registration.'))
 elif choice == '3':
 data = {':action': 'password_reset'}
 data['email'] = ''
 while not data['email']:
 data['email'] = input('Your email address: ')
 code, result = self.post_to_server(data)
- print('Server response (%s): %s'%(code, result))
+ log.info('Server response (%s): %s' % (code, result))
 
 def build_post_data(self, action):
 # figure the data to send - the metadata plus some additional
@@ -254,8 +254,10 @@
 def post_to_server(self, data, auth=None):
 ''' Post a query to the server, and return a string response.
 '''
- self.announce('Registering %s to %s' % (data['name'],
- self.repository), log.INFO)
+ if 'name' in data:
+ self.announce('Registering %s to %s' % (data['name'],
+ self.repository),
+ log.INFO)
 # Build up the MIME payload for the urllib2 POST data
 boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
 sep_boundary = '\n--' + boundary
@@ -302,5 +304,6 @@
 data = result.read()
 result = 200, 'OK'
 if self.show_response:
- print('-'*75, data, '-'*75)
+ dashes = '-' * 75
+ self.announce('%s%s%s' % (dashes, data, dashes))
 return result
Modified: python/branches/py3k-short-float-repr/Lib/distutils/command/upload.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/command/upload.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/command/upload.py	Sun Apr 5 01:04:14 2009
@@ -194,4 +194,4 @@
 self.announce('Upload failed (%s): %s' % (r.status, r.reason),
 log.ERROR)
 if self.show_response:
- print('-'*75, r.read(), '-'*75)
+ self.announce('-'*75, r.read(), '-'*75)
Modified: python/branches/py3k-short-float-repr/Lib/distutils/extension.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/extension.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/extension.py	Sun Apr 5 01:04:14 2009
@@ -82,6 +82,9 @@
 language : string
 extension language (i.e. "c", "c++", "objc"). Will be detected
 from the source extensions if not provided.
+ optional : boolean
+ specifies that a build failure in the extension should not abort the
+ build process, but simply not install the failing extension.
 """
 
 # When adding arguments to this constructor, be sure to update
@@ -100,6 +103,7 @@
 swig_opts = None,
 depends=None,
 language=None,
+ optional=None,
 **kw # To catch unknown keywords
 ):
 assert isinstance(name, str), "'name' must be a string"
@@ -122,6 +126,7 @@
 self.swig_opts = swig_opts or []
 self.depends = depends or []
 self.language = language
+ self.optional = optional
 
 # If there are unknown keyword options, warn about them
 if len(kw):
Modified: python/branches/py3k-short-float-repr/Lib/distutils/tests/support.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/tests/support.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/tests/support.py	Sun Apr 5 01:04:14 2009
@@ -4,7 +4,7 @@
 import tempfile
 
 from distutils import log
-
+from distutils.core import Distribution
 
 class LoggingSilencer(object):
 
@@ -42,7 +42,7 @@
 self.tempdirs.append(d)
 return d
 
- def write_file(self, path, content):
+ def write_file(self, path, content='xxx'):
 """Writes a file in the given path.
 
 
@@ -56,6 +56,23 @@
 finally:
 f.close()
 
+ def create_dist(self, pkg_name='foo', **kw):
+ """Will generate a test environment.
+
+ This function creates:
+ - a Distribution instance using keywords
+ - a temporary directory with a package structure
+
+ It returns the package directory and the distribution
+ instance.
+ """
+ tmp_dir = self.mkdtemp()
+ pkg_dir = os.path.join(tmp_dir, pkg_name)
+ os.mkdir(pkg_dir)
+ dist = Distribution(attrs=kw)
+
+ return pkg_dir, dist
+
 class DummyCommand:
 """Class to store options for retrieval via set_undefined_options()."""
 
Modified: python/branches/py3k-short-float-repr/Lib/distutils/tests/test_build_ext.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/tests/test_build_ext.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/tests/test_build_ext.py	Sun Apr 5 01:04:14 2009
@@ -8,6 +8,10 @@
 from distutils.command.build_ext import build_ext
 from distutils import sysconfig
 from distutils.tests.support import TempdirManager
+from distutils.tests.support import LoggingSilencer
+from distutils.extension import Extension
+from distutils.errors import UnknownFileError
+from distutils.errors import CompileError
 
 import unittest
 from test import support
@@ -20,7 +24,9 @@
 srcdir = sysconfig.get_config_var('srcdir')
 return os.path.join(srcdir, 'Modules', 'xxmodule.c')
 
-class BuildExtTestCase(TempdirManager, unittest.TestCase):
+class BuildExtTestCase(TempdirManager,
+ LoggingSilencer,
+ unittest.TestCase):
 def setUp(self):
 # Create a simple test environment
 # Note that we're making changes to sys.path
@@ -141,6 +147,23 @@
 self.assert_(lib in cmd.library_dirs)
 self.assert_(incl in cmd.include_dirs)
 
+ def test_optional_extension(self):
+
+ # this extension will fail, but let's ignore this failure
+ # with the optional argument.
+ modules = [Extension('foo', ['xxx'], optional=False)]
+ dist = Distribution({'name': 'xx', 'ext_modules': modules})
+ cmd = build_ext(dist)
+ cmd.ensure_finalized()
+ self.assertRaises((UnknownFileError, CompileError),
+ cmd.run) # should raise an error
+
+ modules = [Extension('foo', ['xxx'], optional=True)]
+ dist = Distribution({'name': 'xx', 'ext_modules': modules})
+ cmd = build_ext(dist)
+ cmd.ensure_finalized()
+ cmd.run() # should pass
+
 def test_suite():
 src = _get_source_filename()
 if not os.path.exists(src):
Modified: python/branches/py3k-short-float-repr/Lib/distutils/tests/test_config.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/tests/test_config.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/tests/test_config.py	Sun Apr 5 01:04:14 2009
@@ -46,7 +46,9 @@
 """
 
 
-class PyPIRCCommandTestCase(support.TempdirManager, unittest.TestCase):
+class PyPIRCCommandTestCase(support.TempdirManager,
+ support.LoggingSilencer,
+ unittest.TestCase):
 
 def setUp(self):
 """Patches the environment."""
Modified: python/branches/py3k-short-float-repr/Lib/distutils/tests/test_msvc9compiler.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/tests/test_msvc9compiler.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/tests/test_msvc9compiler.py	Sun Apr 5 01:04:14 2009
@@ -48,8 +48,8 @@
 v = Reg.get_value(path, "lfitalic")
 self.assert_(v in (0, 1))
 
- import _winreg
- HKCU = _winreg.HKEY_CURRENT_USER
+ import winreg
+ HKCU = winreg.HKEY_CURRENT_USER
 keys = Reg.read_keys(HKCU, 'xxxx')
 self.assertEquals(keys, None)
 
Modified: python/branches/py3k-short-float-repr/Lib/distutils/tests/test_register.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/tests/test_register.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/tests/test_register.py	Sun Apr 5 01:04:14 2009
@@ -3,7 +3,9 @@
 import os
 import unittest
 import getpass
+import urllib
 
+from distutils.command import register as register_module
 from distutils.command.register import register
 from distutils.core import Distribution
 
@@ -42,18 +44,20 @@
 finally:
 self.index += 1
 
-class FakeServer(object):
+class FakeOpener(object):
 """Fakes a PyPI server"""
 def __init__(self):
- self.calls = []
+ self.reqs = []
 
 def __call__(self, *args):
- # we want to compare them, so let's store
- # something comparable
- els = list(args[0].items())
- els.sort()
- self.calls.append(tuple(els))
- return 200, 'OK'
+ return self
+
+ def open(self, req):
+ self.reqs.append(req)
+ return self
+
+ def read(self):
+ return 'xxx'
 
 class registerTestCase(PyPIRCCommandTestCase):
 
@@ -64,24 +68,27 @@
 def _getpass(prompt):
 return 'password'
 getpass.getpass = _getpass
+ self.old_opener = urllib.request.build_opener
+ self.conn = urllib.request.build_opener = FakeOpener()
 
 def tearDown(self):
 getpass.getpass = self._old_getpass
+ urllib.request.build_opener = self.old_opener
 PyPIRCCommandTestCase.tearDown(self)
 
+ def _get_cmd(self):
+ metadata = {'url': 'xxx', 'author': 'xxx',
+ 'author_email': 'xxx',
+ 'name': 'xxx', 'version': 'xxx'}
+ pkg_info, dist = self.create_dist(**metadata)
+ return register(dist)
+
 def test_create_pypirc(self):
 # this test makes sure a .pypirc file
 # is created when requested.
 
- # let's create a fake distribution
- # and a register instance
- dist = Distribution()
- dist.metadata.url = 'xxx'
- dist.metadata.author = 'xxx'
- dist.metadata.author_email = 'xxx'
- dist.metadata.name = 'xxx'
- dist.metadata.version = 'xxx'
- cmd = register(dist)
+ # let's create a register instance
+ cmd = self._get_cmd()
 
 # we shouldn't have a .pypirc file yet
 self.assert_(not os.path.exists(self.rc))
@@ -95,13 +102,12 @@
 # Password : 'password'
 # Save your login (y/N)? : 'y'
 inputs = Inputs('1', 'tarek', 'y')
- from distutils.command import register as register_module
 register_module.input = inputs.__call__
-
- cmd.post_to_server = pypi_server = FakeServer()
-
 # let's run the command
- cmd.run()
+ try:
+ cmd.run()
+ finally:
+ del register_module.input
 
 # we should have a brand new .pypirc file
 self.assert_(os.path.exists(self.rc))
@@ -115,32 +121,68 @@
 # if we run the command again
 def _no_way(prompt=''):
 raise AssertionError(prompt)
- register_module.raw_input = _no_way
+ register_module.input = _no_way
 
+ cmd.show_response = 1
 cmd.run()
 
 # let's see what the server received : we should
 # have 2 similar requests
- self.assert_(len(pypi_server.calls), 2)
- self.assert_(pypi_server.calls[0], pypi_server.calls[1])
+ self.assert_(self.conn.reqs, 2)
+ req1 = dict(self.conn.reqs[0].headers)
+ req2 = dict(self.conn.reqs[1].headers)
+
+ self.assertEquals(req1['Content-length'], '1374')
+ self.assertEquals(req2['Content-length'], '1374')
+ self.assert_((b'xxx') in self.conn.reqs[1].data)
 
 def test_password_not_in_file(self):
 
- f = open(self.rc, 'w')
- f.write(PYPIRC_NOPASSWORD)
- f.close()
-
- dist = Distribution()
- cmd = register(dist)
- cmd.post_to_server = FakeServer()
-
+ self.write_file(self.rc, PYPIRC_NOPASSWORD)
+ cmd = self._get_cmd()
 cmd._set_config()
 cmd.finalize_options()
 cmd.send_metadata()
 
 # dist.password should be set
 # therefore used afterwards by other commands
- self.assertEquals(dist.password, 'password')
+ self.assertEquals(cmd.distribution.password, 'password')
+
+ def test_registering(self):
+ # this test runs choice 2
+ cmd = self._get_cmd()
+ inputs = Inputs('2', 'tarek', 'tarek at ziade.org')
+ register_module.input = inputs.__call__
+ try:
+ # let's run the command
+ cmd.run()
+ finally:
+ del register_module.input
+
+ # we should have send a request
+ self.assert_(self.conn.reqs, 1)
+ req = self.conn.reqs[0]
+ headers = dict(req.headers)
+ self.assertEquals(headers['Content-length'], '608')
+ self.assert_((b'tarek') in req.data)
+
+ def test_password_reset(self):
+ # this test runs choice 3
+ cmd = self._get_cmd()
+ inputs = Inputs('3', 'tarek at ziade.org')
+ register_module.input = inputs.__call__
+ try:
+ # let's run the command
+ cmd.run()
+ finally:
+ del register_module.input
+
+ # we should have send a request
+ self.assert_(self.conn.reqs, 1)
+ req = self.conn.reqs[0]
+ headers = dict(req.headers)
+ self.assertEquals(headers['Content-length'], '290')
+ self.assert_((b'tarek') in req.data)
 
 def test_suite():
 return unittest.makeSuite(registerTestCase)
Modified: python/branches/py3k-short-float-repr/Lib/distutils/tests/test_sdist.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/tests/test_sdist.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/tests/test_sdist.py	Sun Apr 5 01:04:14 2009
@@ -34,7 +34,7 @@
 somecode%(sep)sdoc.txt
 """
 
-class sdistTestCase(support.LoggingSilencer, PyPIRCCommandTestCase):
+class sdistTestCase(PyPIRCCommandTestCase):
 
 def setUp(self):
 # PyPIRCCommandTestCase creates a temp dir already
Modified: python/branches/py3k-short-float-repr/Lib/distutils/tests/test_upload.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/tests/test_upload.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/tests/test_upload.py	Sun Apr 5 01:04:14 2009
@@ -2,6 +2,7 @@
 import sys
 import os
 import unittest
+import http.client as httpclient
 
 from distutils.command.upload import upload
 from distutils.core import Distribution
@@ -18,17 +19,52 @@
 [server1]
 username:me
 """
+class Response(object):
+ def __init__(self, status=200, reason='OK'):
+ self.status = status
+ self.reason = reason
 
+class FakeConnection(object):
+
+ def __init__(self):
+ self.requests = []
+ self.headers = []
+ self.body = ''
+
+ def __call__(self, netloc):
+ return self
+
+ def connect(self):
+ pass
+ endheaders = connect
+
+ def putrequest(self, method, url):
+ self.requests.append((method, url))
+
+ def putheader(self, name, value):
+ self.headers.append((name, value))
+
+ def send(self, body):
+ self.body = body
+
+ def getresponse(self):
+ return Response()
 
 class uploadTestCase(PyPIRCCommandTestCase):
 
+ def setUp(self):
+ super(uploadTestCase, self).setUp()
+ self.old_class = httpclient.HTTPConnection
+ self.conn = httpclient.HTTPConnection = FakeConnection()
+
+ def tearDown(self):
+ httpclient.HTTPConnection = self.old_class
+ super(uploadTestCase, self).tearDown()
+
 def test_finalize_options(self):
 
 # new format
- f = open(self.rc, 'w')
- f.write(PYPIRC)
- f.close()
-
+ self.write_file(self.rc, PYPIRC)
 dist = Distribution()
 cmd = upload(dist)
 cmd.finalize_options()
@@ -39,9 +75,7 @@
 
 def test_saved_password(self):
 # file with no password
- f = open(self.rc, 'w')
- f.write(PYPIRC_NOPASSWORD)
- f.close()
+ self.write_file(self.rc, PYPIRC_NOPASSWORD)
 
 # make sure it passes
 dist = Distribution()
@@ -56,6 +90,28 @@
 cmd.finalize_options()
 self.assertEquals(cmd.password, 'xxx')
 
+ def test_upload(self):
+ tmp = self.mkdtemp()
+ path = os.path.join(tmp, 'xxx')
+ self.write_file(path)
+ command, pyversion, filename = 'xxx', '2.6', path
+ dist_files = [(command, pyversion, filename)]
+ self.write_file(self.rc, PYPIRC)
+
+ # lets run it
+ pkg_dir, dist = self.create_dist(dist_files=dist_files)
+ cmd = upload(dist)
+ cmd.ensure_finalized()
+ cmd.run()
+
+ # what did we send ?
+ headers = dict(self.conn.headers)
+ self.assertEquals(headers['Content-length'], '2087')
+ self.assert_(headers['Content-type'].startswith('multipart/form-data'))
+
+ self.assertEquals(self.conn.requests, [('POST', '/pypi')])
+ self.assert_((b'xxx') in self.conn.body)
+
 def test_suite():
 return unittest.makeSuite(uploadTestCase)
 
Modified: python/branches/py3k-short-float-repr/Lib/distutils/util.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/distutils/util.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/distutils/util.py	Sun Apr 5 01:04:14 2009
@@ -571,6 +571,39 @@
 r = DistutilsRefactoringTool(fixer_names, options=options)
 r.refactor(files, write=True)
 
+def copydir_run_2to3(src, dest, template=None, fixer_names=None,
+ options=None, explicit=None):
+ """Recursively copy a directory, only copying new and changed files,
+ running run_2to3 over all newly copied Python modules afterward.
+
+ If you give a template string, it's parsed like a MANIFEST.in.
+ """
+ from distutils.dir_util import mkpath
+ from distutils.file_util import copy_file
+ from distutils.filelist import FileList
+ filelist = FileList()
+ curdir = os.getcwd()
+ os.chdir(src)
+ try:
+ filelist.findall()
+ finally:
+ os.chdir(curdir)
+ filelist.files[:] = filelist.allfiles
+ if template:
+ for line in template.splitlines():
+ line = line.strip()
+ if not line: continue
+ filelist.process_template_line(line)
+ copied = []
+ for filename in filelist.files:
+ outname = os.path.join(dest, filename)
+ mkpath(os.path.dirname(outname))
+ res = copy_file(os.path.join(src, filename), outname, update=1)
+ if res[1]: copied.append(outname)
+ run_2to3([fn for fn in copied if fn.lower().endswith('.py')],
+ fixer_names=fixer_names, options=options, explicit=explicit)
+ return copied
+
 class Mixin2to3:
 '''Mixin class for commands that run 2to3.
 To configure 2to3, setup scripts may either change
Modified: python/branches/py3k-short-float-repr/Lib/email/generator.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/email/generator.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/email/generator.py	Sun Apr 5 01:04:14 2009
@@ -138,7 +138,7 @@
 else:
 # Header's got lots of smarts, so use it.
 header = Header(v, maxlinelen=self._maxheaderlen,
- header_name=h, continuation_ws='\t')
+ header_name=h)
 print(header.encode(), file=self._fp)
 # A blank line always separates headers from body
 print(file=self._fp)
Modified: python/branches/py3k-short-float-repr/Lib/email/test/test_email.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/email/test/test_email.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/email/test/test_email.py	Sun Apr 5 01:04:14 2009
@@ -769,7 +769,7 @@
 msg['To'] = to
 eq(msg.as_string(maxheaderlen=78), '''\
 To: "Someone Test #A" <someone at eecs.umich.edu>,<someone at eecs.umich.edu>,
-\t"Someone Test #B" <someone at umich.edu>,
+ "Someone Test #B" <someone at umich.edu>,
 "Someone Test #C" <someone at eecs.umich.edu>,
 "Someone Test #D" <someone at eecs.umich.edu>
 
@@ -852,7 +852,7 @@
 # snug against the field name.
 eq(msg.as_string(maxheaderlen=78), """\
 Face-1:\x20
-\tiVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
+ iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
 Face-2:\x20
 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
Modified: python/branches/py3k-short-float-repr/Lib/email/test/test_email_codecs.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/email/test/test_email_codecs.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/email/test/test_email_codecs.py	Sun Apr 5 01:04:14 2009
@@ -6,9 +6,9 @@
 from test.support import run_unittest
 
 from email.test.test_email import TestEmailBase
-from email.Charset import Charset
-from email.Header import Header, decode_header
-from email.Message import Message
+from email.charset import Charset
+from email.header import Header, decode_header
+from email.message import Message
 
 # We're compatible with Python 2.3, but it doesn't have the built-in Asian
 # codecs, so we have to skip all these tests.
Deleted: python/branches/py3k-short-float-repr/Lib/email/test/test_email_codecs_renamed.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/email/test/test_email_codecs_renamed.py	Sun Apr 5 01:04:14 2009
+++ (empty file)
@@ -1,77 +0,0 @@
-# Copyright (C) 2002-2006 Python Software Foundation
-# Contact: email-sig at python.org
-# email package unit tests for (optional) Asian codecs
-
-import unittest
-from test.support import run_unittest
-
-from email.test.test_email import TestEmailBase
-from email.charset import Charset
-from email.header import Header, decode_header
-from email.message import Message
-
-# We're compatible with Python 2.3, but it doesn't have the built-in Asian
-# codecs, so we have to skip all these tests.
-try:
- str('foo', 'euc-jp')
-except LookupError:
- raise unittest.SkipTest
-
-
-
-class TestEmailAsianCodecs(TestEmailBase):
- def test_japanese_codecs(self):
- eq = self.ndiffAssertEqual
- j = Charset("euc-jp")
- g = Charset("iso-8859-1")
- h = Header("Hello World!")
- jhello = '\xa5\xcf\xa5\xed\xa1\xbc\xa5\xef\xa1\xbc\xa5\xeb\xa5\xc9\xa1\xaa'
- ghello = 'Gr\xfc\xdf Gott!'
- h.append(jhello, j)
- h.append(ghello, g)
- # BAW: This used to -- and maybe should -- fold the two iso-8859-1
- # chunks into a single encoded word. However it doesn't violate the
- # standard to have them as two encoded chunks and maybe it's
- # reasonable <wink> for each .append() call to result in a separate
- # encoded word.
- eq(h.encode(), """\
-Hello World! =?iso-2022-jp?b?GyRCJU8lbSE8JW8hPCVrJUkhKhsoQg==?=
- =?iso-8859-1?q?Gr=FC=DF?= =?iso-8859-1?q?_Gott!?=""")
- eq(decode_header(h.encode()),
- [('Hello World!', None),
- ('\x1b$B%O%m!<%o!<%k%I!*\x1b(B', 'iso-2022-jp'),
- ('Gr\xfc\xdf Gott!', 'iso-8859-1')])
- int = 'test-ja \xa4\xd8\xc5\xea\xb9\xc6\xa4\xb5\xa4\xec\xa4\xbf\xa5\xe1\xa1\xbc\xa5\xeb\xa4\xcf\xbb\xca\xb2\xf1\xbc\xd4\xa4\xce\xbe\xb5\xc7\xa7\xa4\xf2\xc2\xd4\xa4\xc3\xa4\xc6\xa4\xa4\xa4\xde\xa4\xb9'
- h = Header(int, j, header_name="Subject")
- # test a very long header
- enc = h.encode()
- # TK: splitting point may differ by codec design and/or Header encoding
- eq(enc , """\
-=?iso-2022-jp?b?dGVzdC1qYSAbJEIkWEVqOUYkNSRsJD8lYSE8JWskTztKGyhC?=
- =?iso-2022-jp?b?GyRCMnE8VCROPjVHJyRyQlQkQyRGJCQkXiQ5GyhC?=""")
- # TK: full decode comparison
- eq(h.__unicode__().encode('euc-jp'), int)
-
- def test_payload_encoding(self):
- jhello = '\xa5\xcf\xa5\xed\xa1\xbc\xa5\xef\xa1\xbc\xa5\xeb\xa5\xc9\xa1\xaa'
- jcode = 'euc-jp'
- msg = Message()
- msg.set_payload(jhello, jcode)
- ustr = str(msg.get_payload(), msg.get_content_charset())
- self.assertEqual(jhello, ustr.encode(jcode))
-
-
-
-def suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(TestEmailAsianCodecs))
- return suite
-
-
-def test_main():
- run_unittest(TestEmailAsianCodecs)
-
-
-
-if __name__ == '__main__':
- unittest.main(defaultTest='suite')
Modified: python/branches/py3k-short-float-repr/Lib/http/client.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/http/client.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/http/client.py	Sun Apr 5 01:04:14 2009
@@ -204,6 +204,12 @@
 MAXAMOUNT = 1048576
 
 class HTTPMessage(email.message.Message):
+ # XXX The only usage of this method is in
+ # http.server.CGIHTTPRequestHandler. Maybe move the code there so
+ # that it doesn't need to be part of the public API. The API has
+ # never been defined so this could cause backwards compatibility
+ # issues.
+
 def getallmatchingheaders(self, name):
 """Find all header lines matching a given header name.
 
@@ -261,20 +267,26 @@
 # text following RFC 2047. The basic status line parsing only
 # accepts iso-8859-1.
 
- def __init__(self, sock, debuglevel=0, strict=0, method=None):
- # If the response includes a content-length header, we
- # need to make sure that the client doesn't read more than the
+ def __init__(self, sock, debuglevel=0, strict=0, method=None, url=None):
+ # If the response includes a content-length header, we need to
+ # make sure that the client doesn't read more than the
 # specified number of bytes. If it does, it will block until
- # the server times out and closes the connection. (The only
- # applies to HTTP/1.1 connections.) This will happen if a self.fp.read()
- # is done (without a size) whether self.fp is buffered or not.
- # So, no self.fp.read() by clients unless they know what they are doing.
+ # the server times out and closes the connection. This will
+ # happen if a self.fp.read() is done (without a size) whether
+ # self.fp is buffered or not. So, no self.fp.read() by
+ # clients unless they know what they are doing.
 self.fp = sock.makefile("rb")
 self.debuglevel = debuglevel
 self.strict = strict
 self._method = method
 
- self.msg = None
+ # The HTTPResponse object is returned via urllib. The clients
+ # of http and urllib expect different attributes for the
+ # headers. headers is used here and supports urllib. msg is
+ # provided as a backwards compatibility layer for http
+ # clients.
+
+ self.headers = self.msg = None
 
 # from the Status-Line of the response
 self.version = _UNKNOWN # HTTP-Version
@@ -326,7 +338,7 @@
 return version, status, reason
 
 def begin(self):
- if self.msg is not None:
+ if self.headers is not None:
 # we've already started reading the response
 return
 
@@ -343,7 +355,7 @@
 if self.debuglevel > 0:
 print("header:", skip)
 
- self.status = status
+ self.code = self.status = status
 self.reason = reason.strip()
 if version == "HTTP/1.0":
 self.version = 10
@@ -358,17 +370,17 @@
 self.length = None
 self.chunked = False
 self.will_close = True
- self.msg = email.message_from_string('')
+ self.headers = self.msg = email.message_from_string('')
 return
 
- self.msg = parse_headers(self.fp)
+ self.headers = self.msg = parse_headers(self.fp)
 
 if self.debuglevel > 0:
- for hdr in self.msg:
+ for hdr in self.headers:
 print("header:", hdr, end=" ")
 
 # are we using the chunked-style of transfer encoding?
- tr_enc = self.msg.get("transfer-encoding")
+ tr_enc = self.headers.get("transfer-encoding")
 if tr_enc and tr_enc.lower() == "chunked":
 self.chunked = True
 self.chunk_left = None
@@ -381,10 +393,10 @@
 # do we have a Content-Length?
 # NOTE: RFC 2616, S4.4, #3 says we ignore this if tr_enc is "chunked"
 self.length = None
- length = self.msg.get("content-length")
+ length = self.headers.get("content-length")
 
 # are we using the chunked-style of transfer encoding?
- tr_enc = self.msg.get("transfer-encoding")
+ tr_enc = self.headers.get("transfer-encoding")
 if length and not self.chunked:
 try:
 self.length = int(length)
@@ -411,11 +423,11 @@
 self.will_close = True
 
 def _check_close(self):
- conn = self.msg.get("connection")
+ conn = self.headers.get("connection")
 if self.version == 11:
 # An HTTP/1.1 proxy is assumed to stay open unless
 # explicitly closed.
- conn = self.msg.get("connection")
+ conn = self.headers.get("connection")
 if conn and "close" in conn.lower():
 return True
 return False
@@ -424,7 +436,7 @@
 # connections, using rules different than HTTP/1.1.
 
 # For older HTTP, Keep-Alive indicates persistent connection.
- if self.msg.get("keep-alive"):
+ if self.headers.get("keep-alive"):
 return False
 
 # At least Akamai returns a "Connection: Keep-Alive" header,
@@ -433,7 +445,7 @@
 return False
 
 # Proxy-Connection is a netscape hack.
- pconn = self.msg.get("proxy-connection")
+ pconn = self.headers.get("proxy-connection")
 if pconn and "keep-alive" in pconn.lower():
 return False
 
@@ -457,6 +469,9 @@
 def flush(self):
 self.fp.flush()
 
+ def readable(self):
+ return True
+
 # End of "raw stream" methods
 
 def isclosed(self):
@@ -584,21 +599,31 @@
 return self.fp.fileno()
 
 def getheader(self, name, default=None):
- if self.msg is None:
+ if self.headers is None:
 raise ResponseNotReady()
- return ', '.join(self.msg.get_all(name, default))
+ return ', '.join(self.headers.get_all(name, default))
 
 def getheaders(self):
 """Return list of (header, value) tuples."""
- if self.msg is None:
+ if self.headers is None:
 raise ResponseNotReady()
- return list(self.msg.items())
+ return list(self.headers.items())
 
 # We override IOBase.__iter__ so that it doesn't check for closed-ness
 
 def __iter__(self):
 return self
 
+ # For compatibility with old-style urllib responses.
+
+ def info(self):
+ return self.headers
+
+ def geturl(self):
+ return self.url
+
+ def getcode(self):
+ return self.status
 
 class HTTPConnection:
 
@@ -757,7 +782,7 @@
 if self.__state == _CS_IDLE:
 self.__state = _CS_REQ_STARTED
 else:
- raise CannotSendRequest()
+ raise CannotSendRequest(self.__state)
 
 # Save the method we use, we need it later in the response phase
 self._method = method
@@ -906,13 +931,23 @@
 self.endheaders(body)
 
 def getresponse(self):
- """Get the response from the server."""
+ """Get the response from the server.
+
+ If the HTTPConnection is in the correct state, returns an
+ instance of HTTPResponse or of whatever object is returned by
+ class the response_class variable.
+
+ If a request has not been sent or if a previous response has
+ not be handled, ResponseNotReady is raised. If the HTTP
+ response indicates that the connection should be closed, then
+ it will be closed before the response is returned. When the
+ connection is closed, the underlying socket is closed.
+ """
 
 # if a prior response has been completed, then forget about it.
 if self.__response and self.__response.isclosed():
 self.__response = None
 
- #
 # if a prior response exists, then it must be completed (otherwise, we
 # cannot read this response's header to determine the connection-close
 # behavior)
@@ -929,7 +964,7 @@
 # isclosed() status to become true.
 #
 if self.__state != _CS_REQ_SENT or self.__response:
- raise ResponseNotReady()
+ raise ResponseNotReady(self.__state)
 
 if self.debuglevel > 0:
 response = self.response_class(self.sock, self.debuglevel,
Modified: python/branches/py3k-short-float-repr/Lib/http/cookies.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/http/cookies.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/http/cookies.py	Sun Apr 5 01:04:14 2009
@@ -392,7 +392,7 @@
 document.cookie = \"%s\";
 // end hiding -->
 </script>
- """ % ( self.OutputString(attrs), )
+ """ % ( self.OutputString(attrs).replace('"',r'\"'))
 # end js_output()
 
 def OutputString(self, attrs=None):
Modified: python/branches/py3k-short-float-repr/Lib/http/server.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/http/server.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/http/server.py	Sun Apr 5 01:04:14 2009
@@ -1082,10 +1082,12 @@
 
 sa = httpd.socket.getsockname()
 print("Serving HTTP on", sa[0], "port", sa[1], "...")
- httpd.serve_forever()
-
+ try:
+ httpd.serve_forever()
+ except KeyboardInterrupt:
+ print("\nKeyboard interrupt received, exiting.")
+ httpd.server_close()
+ sys.exit(0)
 
 if __name__ == '__main__':
- test(HandlerClass=BaseHTTPRequestHandler)
 test(HandlerClass=SimpleHTTPRequestHandler)
- test(HandlerClass=CGIHTTPRequestHandler)
Modified: python/branches/py3k-short-float-repr/Lib/idlelib/EditorWindow.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/idlelib/EditorWindow.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/idlelib/EditorWindow.py	Sun Apr 5 01:04:14 2009
@@ -107,10 +107,18 @@
 self.text_frame = text_frame = Frame(top)
 self.vbar = vbar = Scrollbar(text_frame, name='vbar')
 self.width = idleConf.GetOption('main','EditorWindow','width')
- self.text = text = MultiCallCreator(Text)(
- text_frame, name='text', padx=5, wrap='none',
- width=self.width,
- height=idleConf.GetOption('main','EditorWindow','height') )
+ text_options = {
+ 'name': 'text',
+ 'padx': 5,
+ 'wrap': 'none',
+ 'width': self.width,
+ 'height': idleConf.GetOption('main', 'EditorWindow', 'height')}
+ if TkVersion >= 8.5:
+ # Starting with tk 8.5 we have to set the new tabstyle option
+ # to 'wordprocessor' to achieve the same display of tabs as in
+ # older tk versions.
+ text_options['tabstyle'] = 'wordprocessor'
+ self.text = text = MultiCallCreator(Text)(text_frame, **text_options)
 self.top.focused_widget = self.text
 
 self.createmenubar()
Modified: python/branches/py3k-short-float-repr/Lib/idlelib/NEWS.txt
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/idlelib/NEWS.txt	(original)
+++ python/branches/py3k-short-float-repr/Lib/idlelib/NEWS.txt	Sun Apr 5 01:04:14 2009
@@ -3,6 +3,16 @@
 
 *Release date: XX-XXX-XXXX*
 
+- Allow multiple IDLE GUI/subprocess pairs to exist simultaneously. Thanks to
+ David Scherer for suggesting the use of an ephemeral port for the GUI.
+ Patch 1529142 Weeble.
+
+- Remove port spec from run.py and fix bug where subprocess fails to
+ extract port from command line when warnings are present.
+
+- Tk 8.5 Text widget requires 'wordprocessor' tabstyle attr to handle
+ mixed space/tab properly. Issue 5120, patch by Guilherme Polo.
+
 - Issue #4815: Offer conversion to UTF-8 if source files have
 no encoding declaration and are not encoded in UTF-8.
 
Modified: python/branches/py3k-short-float-repr/Lib/idlelib/PyShell.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/idlelib/PyShell.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/idlelib/PyShell.py	Sun Apr 5 01:04:14 2009
@@ -34,7 +34,8 @@
 from idlelib import RemoteDebugger
 from idlelib import macosxSupport
 
-LOCALHOST = '127.0.0.1'
+HOST = '127.0.0.1' # python execution server on localhost loopback
+PORT = 0 # someday pass in host, port for remote debug capability
 
 try:
 from signal import SIGTERM
@@ -339,17 +340,21 @@
 InteractiveInterpreter.__init__(self, locals=locals)
 self.save_warnings_filters = None
 self.restarting = False
- self.subprocess_arglist = self.build_subprocess_arglist()
+ self.subprocess_arglist = None
+ self.port = PORT
 
- port = 8833
 rpcclt = None
 rpcpid = None
 
 def spawn_subprocess(self):
+ if self.subprocess_arglist == None:
+ self.subprocess_arglist = self.build_subprocess_arglist()
 args = self.subprocess_arglist
 self.rpcpid = os.spawnv(os.P_NOWAIT, sys.executable, args)
 
 def build_subprocess_arglist(self):
+ assert (self.port!=0), (
+ "Socket should have been assigned a port number.")
 w = ['-W' + s for s in sys.warnoptions]
 # Maybe IDLE is installed and is being accessed via sys.path,
 # or maybe it's not installed and the idle.py script is being
@@ -368,11 +373,8 @@
 return [decorated_exec] + w + ["-c", command, str(self.port)]
 
 def start_subprocess(self):
- # spawning first avoids passing a listening socket to the subprocess
- self.spawn_subprocess()
- #time.sleep(20) # test to simulate GUI not accepting connection
- addr = (LOCALHOST, self.port)
- # Idle starts listening for connection on localhost
+ addr = (HOST, self.port)
+ # GUI makes several attempts to acquire socket, listens for connection
 for i in range(3):
 time.sleep(i)
 try:
@@ -383,6 +385,18 @@
 else:
 self.display_port_binding_error()
 return None
+ # if PORT was 0, system will assign an 'ephemeral' port. Find it out:
+ self.port = self.rpcclt.listening_sock.getsockname()[1]
+ # if PORT was not 0, probably working with a remote execution server
+ if PORT != 0:
+ # To allow reconnection within the 2MSL wait (cf. Stevens TCP
+ # V1, 18.6), set SO_REUSEADDR. Note that this can be problematic
+ # on Windows since the implementation allows two active sockets on
+ # the same address!
+ self.rpcclt.listening_sock.setsockopt(socket.SOL_SOCKET,
+ socket.SO_REUSEADDR, 1)
+ self.spawn_subprocess()
+ #time.sleep(20) # test to simulate GUI not accepting connection
 # Accept the connection from the Python execution server
 self.rpcclt.listening_sock.settimeout(10)
 try:
@@ -734,13 +748,12 @@
 def display_port_binding_error(self):
 tkMessageBox.showerror(
 "Port Binding Error",
- "IDLE can't bind TCP/IP port 8833, which is necessary to "
- "communicate with its Python execution server. Either "
- "no networking is installed on this computer or another "
- "process (another IDLE?) is using the port. Run IDLE with the -n "
- "command line switch to start without a subprocess and refer to "
- "Help/IDLE Help 'Running without a subprocess' for further "
- "details.",
+ "IDLE can't bind to a TCP/IP port, which is necessary to "
+ "communicate with its Python execution server. This might be "
+ "because no networking is installed on this computer. "
+ "Run IDLE with the -n command line switch to start without a "
+ "subprocess and refer to Help/IDLE Help 'Running without a "
+ "subprocess' for further details.",
 master=self.tkconsole.text)
 
 def display_no_subprocess_error(self):
@@ -1285,7 +1298,7 @@
 global flist, root, use_subprocess
 
 use_subprocess = True
- enable_shell = False
+ enable_shell = True
 enable_edit = False
 debug = False
 cmd = None
@@ -1306,6 +1319,7 @@
 enable_shell = True
 if o == '-e':
 enable_edit = True
+ enable_shell = False
 if o == '-h':
 sys.stdout.write(usage_msg)
 sys.exit()
@@ -1356,7 +1370,6 @@
 edit_start = idleConf.GetOption('main', 'General',
 'editor-on-startup', type='bool')
 enable_edit = enable_edit or edit_start
- enable_shell = enable_shell or not edit_start
 # start editor and/or shell windows:
 root = Tk(className="Idle")
 
Modified: python/branches/py3k-short-float-repr/Lib/idlelib/idlever.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/idlelib/idlever.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/idlelib/idlever.py	Sun Apr 5 01:04:14 2009
@@ -1 +1 @@
-IDLE_VERSION = "3.1a1"
+IDLE_VERSION = "3.1a2"
Modified: python/branches/py3k-short-float-repr/Lib/idlelib/rpc.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/idlelib/rpc.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/idlelib/rpc.py	Sun Apr 5 01:04:14 2009
@@ -518,8 +518,6 @@
 
 def __init__(self, address, family=socket.AF_INET, type=socket.SOCK_STREAM):
 self.listening_sock = socket.socket(family, type)
- self.listening_sock.setsockopt(socket.SOL_SOCKET,
- socket.SO_REUSEADDR, 1)
 self.listening_sock.bind(address)
 self.listening_sock.listen(1)
 
Modified: python/branches/py3k-short-float-repr/Lib/idlelib/run.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/idlelib/run.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/idlelib/run.py	Sun Apr 5 01:04:14 2009
@@ -67,10 +67,14 @@
 global quitting
 global no_exitfunc
 no_exitfunc = del_exitfunc
- port = 8833
 #time.sleep(15) # test subprocess not responding
- if sys.argv[1:]:
- port = int(sys.argv[1])
+ try:
+ assert(len(sys.argv) > 1)
+ port = int(sys.argv[-1])
+ except:
+ print("IDLE Subprocess: no IP port passed in sys.argv.",
+ file=sys.__stderr__)
+ return
 sys.argv[:] = [""]
 sockthread = threading.Thread(target=manage_socket,
 name='SockThread',
Modified: python/branches/py3k-short-float-repr/Lib/importlib/_bootstrap.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/importlib/_bootstrap.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/importlib/_bootstrap.py	Sun Apr 5 01:04:14 2009
@@ -475,25 +475,6 @@
 # Not a property so that it is easy to override.
 return self._find_path(imp.PY_SOURCE)
 
- @_check_name
- def get_source(self, fullname):
- """Return the source for the module as a string.
-
- Return None if the source is not available. Raise ImportError if the
- laoder cannot handle the specified module.
-
- """
- source_path = self._source_path(name)
- if source_path is None:
- return None
- import tokenize
- with _closing(_io.FileIO(source_path, 'r')) as file: # Assuming bytes.
- encoding, lines = tokenize.detect_encoding(file.readline)
- # XXX Will fail when passed to compile() if the encoding is
- # anything other than UTF-8.
- return open(source_path, encoding=encoding).read()
-
-
 def get_data(self, path):
 """Return the data from path as raw bytes."""
 return _io.FileIO(path, 'r').read() # Assuming bytes.
@@ -661,9 +642,10 @@
 finder = cls._path_importer_cache(entry)
 except ImportError:
 continue
- loader = finder.find_module(fullname)
- if loader:
- return loader
+ if finder:
+ loader = finder.find_module(fullname)
+ if loader:
+ return loader
 else:
 return None
 
Modified: python/branches/py3k-short-float-repr/Lib/importlib/test/import_/test_path.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/importlib/test/import_/test_path.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/importlib/test/import_/test_path.py	Sun Apr 5 01:04:14 2009
@@ -55,6 +55,25 @@
 self.assert_(path in sys.path_importer_cache)
 self.assert_(sys.path_importer_cache[path] is importer)
 
+ def test_path_importer_cache_has_None(self):
+ # Test that if sys.path_importer_cache has None that None is returned.
+ clear_cache = {path: None for path in sys.path}
+ with util.import_state(path_importer_cache=clear_cache):
+ for name in ('asynchat', 'sys', '<test module>'):
+ self.assert_(machinery.PathFinder.find_module(name) is None)
+
+ def test_path_importer_cache_has_None_continues(self):
+ # Test that having None in sys.path_importer_cache causes the search to
+ # continue.
+ path = '<test path>'
+ module = '<test module>'
+ importer = util.mock_modules(module)
+ with util.import_state(path=['1', '2'],
+ path_importer_cache={'1': None, '2': importer}):
+ loader = machinery.PathFinder.find_module(module)
+ self.assert_(loader is importer)
+
+
 
 class DefaultPathFinderTests(unittest.TestCase):
 
Modified: python/branches/py3k-short-float-repr/Lib/importlib/test/source/test_abc_loader.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/importlib/test/source/test_abc_loader.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/importlib/test/source/test_abc_loader.py	Sun Apr 5 01:04:14 2009
@@ -123,11 +123,13 @@
 
 def eq_attrs(self, ob, **kwargs):
 for attr, val in kwargs.items():
- self.assertEqual(getattr(ob, attr), val)
+ found = getattr(ob, attr)
+ self.assertEqual(found, val,
+ "{} attribute: {} != {}".format(attr, found, val))
 
 def test_module(self):
 name = '<module>'
- path = 'path/to/module'
+ path = os.path.join('', 'path', 'to', 'module')
 mock = self.mocker({name: path})
 with util.uncache(name):
 module = mock.load_module(name)
@@ -139,7 +141,7 @@
 
 def test_package(self):
 name = '<pkg>'
- path = '/path/to/<pkg>/__init__'
+ path = os.path.join('path', 'to', name, '__init__')
 mock = self.mocker({name: path})
 with util.uncache(name):
 module = mock.load_module(name)
@@ -151,7 +153,7 @@
 
 def test_lacking_parent(self):
 name = 'pkg.mod'
- path = 'path/to/pkg/mod'
+ path = os.path.join('path', 'to', 'pkg', 'mod')
 mock = self.mocker({name: path})
 with util.uncache(name):
 module = mock.load_module(name)
@@ -163,7 +165,7 @@
 
 def test_module_reuse(self):
 name = 'mod'
- path = 'path/to/mod'
+ path = os.path.join('path', 'to', 'mod')
 module = imp.new_module(name)
 mock = self.mocker({name: path})
 with util.uncache(name):
@@ -177,7 +179,7 @@
 name = "mod"
 module = imp.new_module(name)
 module.blah = None
- mock = self.mocker({name: 'path/to/mod'})
+ mock = self.mocker({name: os.path.join('path', 'to', 'mod')})
 mock.source = b"1/0"
 with util.uncache(name):
 sys.modules[name] = module
@@ -188,7 +190,7 @@
 
 def test_unloadable(self):
 name = "mod"
- mock = self.mocker({name: 'path/to/mod'})
+ mock = self.mocker({name: os.path.join('path', 'to', 'mod')})
 mock.source = b"1/0"
 with util.uncache(name):
 self.assertRaises(ZeroDivisionError, mock.load_module, name)
@@ -222,7 +224,7 @@
 def test_default_encoding(self):
 # Should have no problems with UTF-8 text.
 name = 'mod'
- mock = PyLoaderMock({name: 'path/to/mod'})
+ mock = PyLoaderMock({name: os.path.join('path', 'to', 'mod')})
 source = 'x = "ü"'
 mock.source = source.encode('utf-8')
 returned_source = mock.get_source(name)
@@ -231,7 +233,7 @@
 def test_decoded_source(self):
 # Decoding should work.
 name = 'mod'
- mock = PyLoaderMock({name: 'path/to/mod'})
+ mock = PyLoaderMock({name: os.path.join('path', 'to', 'mod')})
 source = "# coding: Latin-1\nx='ü'"
 assert source.encode('latin-1') != source.encode('utf-8')
 mock.source = source.encode('latin-1')
@@ -287,7 +289,7 @@
 @source_util.writes_bytecode
 def run_test(self, dont_write_bytecode):
 name = 'mod'
- mock = PyPycLoaderMock({name: 'path/to/mod'})
+ mock = PyPycLoaderMock({name: os.path.join('path', 'to', 'mod')})
 sys.dont_write_bytecode = dont_write_bytecode
 with util.uncache(name):
 mock.load_module(name)
@@ -311,8 +313,9 @@
 name = 'mod'
 bad_magic = b'\x00\x00\x00\x00'
 assert bad_magic != imp.get_magic()
- mock = PyPycLoaderMock({name: 'path/to/mod'},
- {name: {'path': 'path/to/mod.bytecode',
+ mock = PyPycLoaderMock({name: os.path.join('path', 'to', 'mod')},
+ {name: {'path': os.path.join('path', 'to',
+ 'mod.bytecode'),
 'magic': bad_magic}})
 with util.uncache(name):
 mock.load_module(name)
@@ -325,7 +328,7 @@
 # Bytecode with an older mtime should be regenerated.
 name = 'mod'
 old_mtime = PyPycLoaderMock.default_mtime - 1
- mock = PyPycLoaderMock({name: 'path/to/mod'},
+ mock = PyPycLoaderMock({name: os.path.join('path', 'to', 'mod')},
 {name: {'path': 'path/to/mod.bytecode', 'mtime': old_mtime}})
 with util.uncache(name):
 mock.load_module(name)
@@ -343,7 +346,8 @@
 # A bad magic number should lead to an ImportError.
 name = 'mod'
 bad_magic = b'\x00\x00\x00\x00'
- mock = PyPycLoaderMock({}, {name: {'path': 'path/to/mod',
+ mock = PyPycLoaderMock({}, {name: {'path': os.path.join('path', 'to',
+ 'mod'),
 'magic': bad_magic}})
 with util.uncache(name):
 self.assertRaises(ImportError, mock.load_module, name)
@@ -351,7 +355,9 @@
 def test_bad_bytecode(self):
 # Bad code object bytecode should elad to an ImportError.
 name = 'mod'
- mock = PyPycLoaderMock({}, {name: {'path': '/path/to/mod', 'bc': b''}})
+ mock = PyPycLoaderMock({}, {name: {'path': os.path.join('path', 'to',
+ 'mod'),
+ 'bc': b''}})
 with util.uncache(name):
 self.assertRaises(ImportError, mock.load_module, name)
 
@@ -387,14 +393,15 @@
 def test_source_path_ImportError(self):
 # An ImportError from source_path should trigger an ImportError.
 name = 'mod'
- mock = PyPycLoaderMock({}, {name: {'path': 'path/to/mod'}})
+ mock = PyPycLoaderMock({}, {name: {'path': os.path.join('path', 'to',
+ 'mod')}})
 with util.uncache(name):
 self.assertRaises(ImportError, mock.load_module, name)
 
 def test_bytecode_path_ImportError(self):
 # An ImportError from bytecode_path should trigger an ImportError.
 name = 'mod'
- mock = PyPycLoaderMock({name: 'path/to/mod'})
+ mock = PyPycLoaderMock({name: os.path.join('path', 'to', 'mod')})
 bad_meth = types.MethodType(raise_ImportError, mock)
 mock.bytecode_path = bad_meth
 with util.uncache(name):
Modified: python/branches/py3k-short-float-repr/Lib/importlib/test/util.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/importlib/test/util.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/importlib/test/util.py	Sun Apr 5 01:04:14 2009
@@ -1,7 +1,7 @@
 from contextlib import contextmanager
 import imp
 import os.path
-from test.support import unlink
+from test import support
 import unittest
 import sys
 
@@ -10,6 +10,13 @@
 """Class decorator that nullifies tests that require a case-insensitive
 file system."""
 if sys.platform not in ('win32', 'darwin', 'cygwin'):
+ original_name = os.listdir('.')[0]
+ if original_name.upper() != original_name:
+ changed_name = original_name.upper()
+ else:
+ changed_name = original_name.lower()
+ if os.path.exists(changed_name):
+ return class_
 return unittest.TestCase
 else:
 return class_
Modified: python/branches/py3k-short-float-repr/Lib/io.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/io.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/io.py	Sun Apr 5 01:04:14 2009
@@ -52,7 +52,8 @@
 __all__ = ["BlockingIOError", "open", "IOBase", "RawIOBase", "FileIO",
 "BytesIO", "StringIO", "BufferedIOBase",
 "BufferedReader", "BufferedWriter", "BufferedRWPair",
- "BufferedRandom", "TextIOBase", "TextIOWrapper"]
+ "BufferedRandom", "TextIOBase", "TextIOWrapper",
+ "SEEK_SET", "SEEK_CUR", "SEEK_END"]
 
 
 import _io
@@ -65,6 +66,11 @@
 
 OpenWrapper = _io.open # for compatibility with _pyio
 
+# for seek()
+SEEK_SET = 0
+SEEK_CUR = 1
+SEEK_END = 2
+
 # Declaring ABCs in C is tricky so we do it here.
 # Method descriptions and default implementations are inherited from the C
 # version however.
Modified: python/branches/py3k-short-float-repr/Lib/locale.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/locale.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/locale.py	Sun Apr 5 01:04:14 2009
@@ -11,7 +11,11 @@
 
 """
 
-import sys, encodings, encodings.aliases
+import sys
+import encodings
+import encodings.aliases
+import re
+import collections
 from builtins import str as _builtin_str
 import functools
 
@@ -173,6 +177,9 @@
 amount -= 1
 return s[lpos:rpos+1]
 
+_percent_re = re.compile(r'%(?:\((?P<key>.*?)\))?'
+ r'(?P<modifiers>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]')
+
 def format(percent, value, grouping=False, monetary=False, *additional):
 """Returns the locale-aware substitution of a %? specifier
 (percent).
@@ -180,9 +187,13 @@
 additional is for format strings which contain one or more
 '*' modifiers."""
 # this is only for one-percent-specifier strings and this should be checked
- if percent[0] != '%':
- raise ValueError("format() must be given exactly one %char "
- "format specifier")
+ match = _percent_re.match(percent)
+ if not match or len(match.group())!= len(percent):
+ raise ValueError(("format() must be given exactly one %%char "
+ "format specifier, %s not valid") % repr(percent))
+ return _format(percent, value, grouping, monetary, *additional)
+
+def _format(percent, value, grouping=False, monetary=False, *additional):
 if additional:
 formatted = percent % ((value,) + additional)
 else:
@@ -206,10 +217,6 @@
 formatted = _strip_padding(formatted, seps)
 return formatted
 
-import re, collections
-_percent_re = re.compile(r'%(?:\((?P<key>.*?)\))?'
- r'(?P<modifiers>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]')
-
 def format_string(f, val, grouping=False):
 """Formats a string in the same way that the % formatting would use,
 but takes the current locale into account.
Modified: python/branches/py3k-short-float-repr/Lib/mailbox.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/mailbox.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/mailbox.py	Sun Apr 5 01:04:14 2009
@@ -907,7 +907,7 @@
 _unlock_file(f)
 finally:
 f.close()
- for name, key_list in self.get_sequences():
+ for name, key_list in self.get_sequences().items():
 if key in key_list:
 msg.add_sequence(name)
 return msg
Modified: python/branches/py3k-short-float-repr/Lib/multiprocessing/queues.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/multiprocessing/queues.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/multiprocessing/queues.py	Sun Apr 5 01:04:14 2009
@@ -6,7 +6,7 @@
 # Copyright (c) 2006-2008, R Oudkerk --- see COPYING.txt
 #
 
-__all__ = ['Queue', 'SimpleQueue']
+__all__ = ['Queue', 'SimpleQueue', 'JoinableQueue']
 
 import sys
 import os
Modified: python/branches/py3k-short-float-repr/Lib/site.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/site.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/site.py	Sun Apr 5 01:04:14 2009
@@ -268,13 +268,15 @@
 
 if sys.platform == "darwin":
 # for framework builds *only* we add the standard Apple
- # locations. Currently only per-user, but /Library and
- # /Network/Library could be added too
+ # locations.
 if 'Python.framework' in prefix:
 sitedirs.append(
 os.path.expanduser(
 os.path.join("~", "Library", "Python",
 sys.version[:3], "site-packages")))
+ sitedirs.append(
+ os.path.join("/Library", "Python",
+ sys.version[:3], "site-packages"))
 
 for sitedir in sitedirs:
 if os.path.isdir(sitedir):
Modified: python/branches/py3k-short-float-repr/Lib/symtable.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/symtable.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/symtable.py	Sun Apr 5 01:04:14 2009
@@ -191,6 +191,9 @@
 def is_global(self):
 return bool(self.__scope in (GLOBAL_IMPLICIT, GLOBAL_EXPLICIT))
 
+ def is_declared_global(self):
+ return bool(self.__scope == GLOBAL_EXPLICIT)
+
 def is_local(self):
 return bool(self.__flags & DEF_BOUND)
 
Modified: python/branches/py3k-short-float-repr/Lib/test/buffer_tests.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/buffer_tests.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/buffer_tests.py	Sun Apr 5 01:04:14 2009
@@ -112,7 +112,7 @@
 self.assertEqual(b'abc ', self.marshal(b'abc').ljust(6))
 self.assertEqual(b'abc', self.marshal(b'abc').ljust(3))
 self.assertEqual(b'abc', self.marshal(b'abc').ljust(2))
- self.assertEqual(b'abc*******', self.marshal(b'abc').ljust(10, '*'))
+ self.assertEqual(b'abc*******', self.marshal(b'abc').ljust(10, b'*'))
 self.assertRaises(TypeError, self.marshal(b'abc').ljust)
 
 def test_rjust(self):
@@ -120,7 +120,7 @@
 self.assertEqual(b' abc', self.marshal(b'abc').rjust(6))
 self.assertEqual(b'abc', self.marshal(b'abc').rjust(3))
 self.assertEqual(b'abc', self.marshal(b'abc').rjust(2))
- self.assertEqual(b'*******abc', self.marshal(b'abc').rjust(10, '*'))
+ self.assertEqual(b'*******abc', self.marshal(b'abc').rjust(10, b'*'))
 self.assertRaises(TypeError, self.marshal(b'abc').rjust)
 
 def test_center(self):
@@ -128,7 +128,7 @@
 self.assertEqual(b' abc ', self.marshal(b'abc').center(6))
 self.assertEqual(b'abc', self.marshal(b'abc').center(3))
 self.assertEqual(b'abc', self.marshal(b'abc').center(2))
- self.assertEqual(b'***abc****', self.marshal(b'abc').center(10, '*'))
+ self.assertEqual(b'***abc****', self.marshal(b'abc').center(10, b'*'))
 self.assertRaises(TypeError, self.marshal(b'abc').center)
 
 def test_swapcase(self):
Modified: python/branches/py3k-short-float-repr/Lib/test/regrtest.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/regrtest.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/regrtest.py	Sun Apr 5 01:04:14 2009
@@ -404,8 +404,9 @@
 print("Using random seed", random_seed)
 random.shuffle(tests)
 if trace:
- import trace
- tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix],
+ import trace, tempfile
+ tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix,
+ tempfile.gettempdir()],
 trace=False, count=True)
 test_times = []
 support.verbose = verbose # Tell tests to be moderately quiet
@@ -628,7 +629,7 @@
 print(test, "skipped --", msg)
 sys.stdout.flush()
 return -2
- except (ImportError, unittest.SkipTest) as msg:
+ except unittest.SkipTest as msg:
 if not quiet:
 print(test, "skipped --", msg)
 sys.stdout.flush()
@@ -892,6 +893,7 @@
 test_fork1
 test_epoll
 test_dbm_gnu
+ test_dbm_ndbm
 test_grp
 test_ioctl
 test_largefile
Modified: python/branches/py3k-short-float-repr/Lib/test/support.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/support.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/support.py	Sun Apr 5 01:04:14 2009
@@ -12,6 +12,7 @@
 import shutil
 import warnings
 import unittest
+import importlib
 
 __all__ = ["Error", "TestFailed", "ResourceDenied", "import_module",
 "verbose", "use_resources", "max_memuse", "record_original_stdout",
@@ -24,7 +25,7 @@
 "TransientResource", "transient_internet", "run_with_locale",
 "set_memlimit", "bigmemtest", "bigaddrspacetest", "BasicTestRunner",
 "run_unittest", "run_doctest", "threading_setup", "threading_cleanup",
- "reap_children", "cpython_only", "check_impl_detail"]
+ "reap_children", "cpython_only", "check_impl_detail", "get_attribute"]
 
 class Error(Exception):
 """Base class for regression test exceptions."""
@@ -41,19 +42,32 @@
 """
 
 def import_module(name, deprecated=False):
- """Import the module to be tested, raising SkipTest if it is not
- available."""
+ """Import and return the module to be tested, raising SkipTest if
+ it is not available.
+
+ If deprecated is True, any module or package deprecation messages
+ will be suppressed."""
 with warnings.catch_warnings():
 if deprecated:
 warnings.filterwarnings("ignore", ".+ (module|package)",
 DeprecationWarning)
 try:
- module = __import__(name, level=0)
- except ImportError:
- raise unittest.SkipTest("No module named " + name)
+ module = importlib.import_module(name)
+ except ImportError as msg:
+ raise unittest.SkipTest(str(msg))
 else:
 return module
 
+def get_attribute(obj, name):
+ """Get an attribute, raising SkipTest if AttributeError is raised."""
+ try:
+ attribute = getattr(obj, name)
+ except AttributeError:
+ raise unittest.SkipTest("module %s has no attribute %s" % (
+ obj.__name__, name))
+ else:
+ return attribute
+
 verbose = 1 # Flag set to 0 by regrtest.py
 use_resources = None # Flag set to [] by regrtest.py
 max_memuse = 0 # Disable bigmem tests (they will still be run with
Modified: python/branches/py3k-short-float-repr/Lib/test/test___all__.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test___all__.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test___all__.py	Sun Apr 5 01:04:14 2009
@@ -75,6 +75,8 @@
 self.check_all("heapq")
 self.check_all("http.client")
 self.check_all("ihooks")
+ self.check_all("io")
+ self.check_all("_pyio")
 self.check_all("imaplib")
 self.check_all("imghdr")
 self.check_all("keyword")
Modified: python/branches/py3k-short-float-repr/Lib/test/test_asynchat.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_asynchat.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_asynchat.py	Sun Apr 5 01:04:14 2009
@@ -1,10 +1,13 @@
-# test asynchat -- requires threading
+# test asynchat
+
+from test import support
+
+# If this fails, the test will be skipped.
+thread = support.import_module('_thread')
 
-import _thread as thread # If this fails, we can't test this module
 import asyncore, asynchat, socket, threading, time
 import unittest
 import sys
-from test import support
 
 HOST = support.HOST
 SERVER_QUIT = b'QUIT\n'
Modified: python/branches/py3k-short-float-repr/Lib/test/test_bz2.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_bz2.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_bz2.py	Sun Apr 5 01:04:14 2009
@@ -8,7 +8,9 @@
 import subprocess
 import sys
 
-import bz2
+# Skip tests if the bz2 module doesn't exist.
+bz2 = support.import_module('bz2')
+
 from bz2 import BZ2File, BZ2Compressor, BZ2Decompressor
 
 has_cmdline_bunzip2 = sys.platform not in ("win32", "os2emx")
Modified: python/branches/py3k-short-float-repr/Lib/test/test_collections.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_collections.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_collections.py	Sun Apr 5 01:04:14 2009
@@ -51,12 +51,12 @@
 
 def test_name_fixer(self):
 for spec, renamed in [
- [('efg', 'g%hi'), ('efg', '_2')], # field with non-alpha char
- [('abc', 'class'), ('abc', '_2')], # field has keyword
- [('8efg', '9ghi'), ('_1', '_2')], # field starts with digit
- [('abc', '_efg'), ('abc', '_2')], # field with leading underscore
- [('abc', 'efg', 'efg', 'ghi'), ('abc', 'efg', '_3', 'ghi')], # duplicate field
- [('abc', '', 'x'), ('abc', '_2', 'x')], # fieldname is a space
+ [('efg', 'g%hi'), ('efg', '_1')], # field with non-alpha char
+ [('abc', 'class'), ('abc', '_1')], # field has keyword
+ [('8efg', '9ghi'), ('_0', '_1')], # field starts with digit
+ [('abc', '_efg'), ('abc', '_1')], # field with leading underscore
+ [('abc', 'efg', 'efg', 'ghi'), ('abc', 'efg', '_2', 'ghi')], # duplicate field
+ [('abc', '', 'x'), ('abc', '_1', 'x')], # fieldname is a space
 ]:
 self.assertEqual(namedtuple('NT', spec, rename=True)._fields, renamed)
 
@@ -327,6 +327,25 @@
 B.register(C)
 self.failUnless(issubclass(C, B))
 
+class WithSet(MutableSet):
+
+ def __init__(self, it=()):
+ self.data = set(it)
+
+ def __len__(self):
+ return len(self.data)
+
+ def __iter__(self):
+ return iter(self.data)
+
+ def __contains__(self, item):
+ return item in self.data
+
+ def add(self, item):
+ self.data.add(item)
+
+ def discard(self, item):
+ self.data.discard(item)
 
 class TestCollectionABCs(ABCTestCase):
 
@@ -363,6 +382,12 @@
 self.validate_abstract_methods(MutableSet, '__contains__', '__iter__', '__len__',
 'add', 'discard')
 
+ def test_issue_5647(self):
+ # MutableSet.__iand__ mutated the set during iteration
+ s = WithSet('abcd')
+ s &= WithSet('cdef') # This used to fail
+ self.assertEqual(set(s), set('cd'))
+
 def test_issue_4920(self):
 # MutableSet.pop() method did not work
 class MySet(collections.MutableSet):
Modified: python/branches/py3k-short-float-repr/Lib/test/test_crypt.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_crypt.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_crypt.py	Sun Apr 5 01:04:14 2009
@@ -1,6 +1,7 @@
 from test import support
 import unittest
-import crypt
+
+crypt = support.import_module('crypt')
 
 class CryptTestCase(unittest.TestCase):
 
Modified: python/branches/py3k-short-float-repr/Lib/test/test_csv.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_csv.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_csv.py	Sun Apr 5 01:04:14 2009
@@ -6,7 +6,7 @@
 import sys
 import os
 import unittest
-from io import StringIO, BytesIO
+from io import StringIO
 from tempfile import TemporaryFile
 import csv
 import gc
@@ -162,6 +162,8 @@
 quoting = csv.QUOTE_NONNUMERIC)
 self._write_test(['a',1,'p,q'], '"a","1","p,q"',
 quoting = csv.QUOTE_ALL)
+ self._write_test(['a\nb',1], '"a\nb","1"',
+ quoting = csv.QUOTE_ALL)
 
 def test_write_escape(self):
 self._write_test(['a',1,'p,q'], 'a,1,"p,q"',
@@ -241,6 +243,7 @@
 # will this fail where locale uses comma for decimals?
 self._read_test([',3,"5",7.3, 9'], [['', 3, '5', 7.3, 9]],
 quoting=csv.QUOTE_NONNUMERIC)
+ self._read_test(['"a\nb", 7'], [['a\nb', ' 7']])
 self.assertRaises(ValueError, self._read_test,
 ['abc,3'], [[]],
 quoting=csv.QUOTE_NONNUMERIC)
@@ -276,6 +279,16 @@
 self.assertRaises(StopIteration, next, r)
 self.assertEqual(r.line_num, 3)
 
+ def test_roundtrip_quoteed_newlines(self):
+ with TemporaryFile("w+", newline='') as fileobj:
+ writer = csv.writer(fileobj)
+ self.assertRaises(TypeError, writer.writerows, None)
+ rows = [['a\nb','b'],['c','x\r\nd']]
+ writer.writerows(rows)
+ fileobj.seek(0)
+ for i, row in enumerate(csv.reader(fileobj)):
+ self.assertEqual(row, rows[i])
+
 class TestDialectRegistry(unittest.TestCase):
 def test_registry_badargs(self):
 self.assertRaises(TypeError, csv.list_dialects, None)
Modified: python/branches/py3k-short-float-repr/Lib/test/test_ctypes.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_ctypes.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_ctypes.py	Sun Apr 5 01:04:14 2009
@@ -1,6 +1,10 @@
 import unittest
 
-from test.support import run_unittest
+from test.support import run_unittest, import_module
+
+# Skip tests if _ctypes module was not built.
+import_module('_ctypes')
+
 import ctypes.test
 
 def test_main():
Modified: python/branches/py3k-short-float-repr/Lib/test/test_curses.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_curses.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_curses.py	Sun Apr 5 01:04:14 2009
@@ -9,16 +9,19 @@
 # Only called, not tested: getmouse(), ungetmouse()
 #
 
-import curses, sys, tempfile, os
-import curses.panel
+import sys, tempfile, os
 
 # Optionally test curses module. This currently requires that the
 # 'curses' resource be given on the regrtest command line using the -u
 # option. If not available, nothing after this line will be executed.
 
-from test.support import requires
+from test.support import requires, import_module
 requires('curses')
 
+# If either of these don't exist, skip the tests.
+curses = import_module('curses')
+curses.panel = import_module('curses.panel')
+
 # XXX: if newterm was supported we could use it instead of initscr and not exit
 term = os.environ.get('TERM')
 if not term or term == 'unknown':
Modified: python/branches/py3k-short-float-repr/Lib/test/test_dbm.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_dbm.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_dbm.py	Sun Apr 5 01:04:14 2009
@@ -3,10 +3,12 @@
 
 import os
 import unittest
-import dbm
 import glob
 import test.support
 
+# Skip tests if dbm module doesn't exist.
+dbm = test.support.import_module('dbm')
+
 _fname = test.support.TESTFN
 
 #
Modified: python/branches/py3k-short-float-repr/Lib/test/test_dbm_gnu.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_dbm_gnu.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_dbm_gnu.py	Sun Apr 5 01:04:14 2009
@@ -1,4 +1,5 @@
-import dbm.gnu as gdbm
+from test import support
+gdbm = support.import_module("dbm.gnu") #skip if not supported
 import unittest
 import os
 from test.support import verbose, TESTFN, run_unittest, unlink
Modified: python/branches/py3k-short-float-repr/Lib/test/test_dbm_ndbm.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_dbm_ndbm.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_dbm_ndbm.py	Sun Apr 5 01:04:14 2009
@@ -1,4 +1,5 @@
 from test import support
+support.import_module("dbm.ndbm") #skip if not supported
 import unittest
 import os
 import random
Modified: python/branches/py3k-short-float-repr/Lib/test/test_exceptions.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_exceptions.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_exceptions.py	Sun Apr 5 01:04:14 2009
@@ -341,6 +341,12 @@
 else:
 self.fail("No exception raised")
 
+ def testInvalidAttrs(self):
+ self.assertRaises(TypeError, setattr, Exception(), '__cause__', 1)
+ self.assertRaises(TypeError, delattr, Exception(), '__cause__')
+ self.assertRaises(TypeError, setattr, Exception(), '__context__', 1)
+ self.assertRaises(TypeError, delattr, Exception(), '__context__')
+
 def testNoneClearsTracebackAttr(self):
 try:
 raise IndexError(4)
Modified: python/branches/py3k-short-float-repr/Lib/test/test_fcntl.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_fcntl.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_fcntl.py	Sun Apr 5 01:04:14 2009
@@ -3,12 +3,15 @@
 OS/2+EMX doesn't support the file locking operations.
 
 """
-import fcntl
 import os
 import struct
 import sys
 import unittest
-from test.support import verbose, TESTFN, unlink, run_unittest
+from test.support import verbose, TESTFN, unlink, run_unittest, import_module
+
+# Skip test if no fnctl module.
+fcntl = import_module('fcntl')
+
 
 # TODO - Write tests for flock() and lockf().
 
Modified: python/branches/py3k-short-float-repr/Lib/test/test_fork1.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_fork1.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_fork1.py	Sun Apr 5 01:04:14 2009
@@ -3,14 +3,12 @@
 
 import os
 import time
-import unittest
 from test.fork_wait import ForkWait
-from test.support import run_unittest, reap_children
+from test.support import run_unittest, reap_children, get_attribute
+
+# Skip test if fork does not exist.
+get_attribute(os, 'fork')
 
-try:
- os.fork
-except AttributeError:
- raise unittest.SkipTest("os.fork not defined -- skipping test_fork1")
 
 class ForkTest(ForkWait):
 def wait_impl(self, cpid):
Modified: python/branches/py3k-short-float-repr/Lib/test/test_functools.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_functools.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_functools.py	Sun Apr 5 01:04:14 2009
@@ -2,6 +2,7 @@
 import unittest
 from test import support
 from weakref import proxy
+import pickle
 
 @staticmethod
 def PythonPartial(func, *args, **keywords):
@@ -19,6 +20,9 @@
 """capture all positional and keyword arguments"""
 return args, kw
 
+def signature(part):
+ """ return the signature of a partial object """
+ return (part.func, part.args, part.keywords, part.__dict__)
 
 class TestPartial(unittest.TestCase):
 
@@ -141,6 +145,12 @@
 join = self.thetype(''.join)
 self.assertEqual(join(data), '0123456789')
 
+ def test_pickle(self):
+ f = self.thetype(signature, 'asdf', bar=True)
+ f.add_something_to__dict__ = True
+ f_copy = pickle.loads(pickle.dumps(f))
+ self.assertEqual(signature(f), signature(f_copy))
+
 class PartialSubclass(functools.partial):
 pass
 
@@ -148,11 +158,13 @@
 
 thetype = PartialSubclass
 
-
 class TestPythonPartial(TestPartial):
 
 thetype = PythonPartial
 
+ # the python version isn't picklable
+ def test_pickle(self): pass
+
 class TestUpdateWrapper(unittest.TestCase):
 
 def check_wrapper(self, wrapper, wrapped,
Modified: python/branches/py3k-short-float-repr/Lib/test/test_gc.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_gc.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_gc.py	Sun Apr 5 01:04:14 2009
@@ -244,7 +244,7 @@
 # - the call to assertEqual somehow avoids building its args tuple
 def test_get_count(self):
 # Avoid future allocation of method object
- assertEqual = self.assertEqual
+ assertEqual = self._baseAssertEqual
 gc.collect()
 assertEqual(gc.get_count(), (0, 0, 0))
 a = dict()
Modified: python/branches/py3k-short-float-repr/Lib/test/test_grp.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_grp.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_grp.py	Sun Apr 5 01:04:14 2009
@@ -1,9 +1,10 @@
 """Test script for the grp module."""
 
-import grp
 import unittest
 from test import support
 
+grp = support.import_module('grp')
+
 class GroupDatabaseTestCase(unittest.TestCase):
 
 def check_value(self, value):
Modified: python/branches/py3k-short-float-repr/Lib/test/test_http_cookiejar.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_http_cookiejar.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_http_cookiejar.py	Sun Apr 5 01:04:14 2009
@@ -583,11 +583,6 @@
 req = urllib.request.Request("http://www.acme.com/",
 headers={"Host": "irrelevant.com"})
 self.assertEquals(request_host(req), "www.acme.com")
- # not actually sure this one is valid Request object, so maybe should
- # remove test for no host in url in request_host function?
- req = urllib.request.Request("/resource.html",
- headers={"Host": "www.acme.com"})
- self.assertEquals(request_host(req), "www.acme.com")
 # port shouldn't be in request-host
 req = urllib.request.Request("http://www.acme.com:2345/resource.html",
 headers={"Host": "www.acme.com:5432"})
Modified: python/branches/py3k-short-float-repr/Lib/test/test_http_cookies.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_http_cookies.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_http_cookies.py	Sun Apr 5 01:04:14 2009
@@ -50,17 +50,17 @@
 
 self.assertEqual(C.output(['path']),
 'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme')
- self.assertEqual(C.js_output(), """
+ self.assertEqual(C.js_output(), r"""
 <script type="text/javascript">
 <!-- begin hiding
- document.cookie = "Customer="WILE_E_COYOTE"; Path=/acme; Version=1";
+ document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1";
 // end hiding -->
 </script>
 """)
- self.assertEqual(C.js_output(['path']), """
+ self.assertEqual(C.js_output(['path']), r"""
 <script type="text/javascript">
 <!-- begin hiding
- document.cookie = "Customer="WILE_E_COYOTE"; Path=/acme";
+ document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme";
 // end hiding -->
 </script>
 """)
Modified: python/branches/py3k-short-float-repr/Lib/test/test_imp.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_imp.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_imp.py	Sun Apr 5 01:04:14 2009
@@ -1,4 +1,7 @@
 import imp
+import locale
+import os
+import os.path
 import sys
 import unittest
 from test import support
@@ -75,6 +78,74 @@
 support.unlink(temp_mod_name + '.pyc')
 support.unlink(temp_mod_name + '.pyo')
 
+ def test_issue5604(self):
+ # Test cannot cover imp.load_compiled function.
+ # Martin von Loewis note what shared library cannot have non-ascii
+ # character because init_xxx function cannot be compiled
+ # and issue never happens for dynamic modules.
+ # But sources modified to follow generic way for processing pathes.
+
+ locale_encoding = locale.getpreferredencoding()
+
+ # covers utf-8 and Windows ANSI code pages
+ # one non-space symbol from every page
+ # (http://en.wikipedia.org/wiki/Code_page)
+ known_locales = {
+ 'utf-8' : b'\xe4',
+ 'cp1250' : b'\x8C',
+ 'cp1251' : b'\xc0',
+ 'cp1252' : b'\xc0',
+ 'cp1253' : b'\xc1',
+ 'cp1254' : b'\xc0',
+ 'cp1255' : b'\xe0',
+ 'cp1256' : b'\xe0',
+ 'cp1257' : b'\xc0',
+ 'cp1258' : b'\xc0',
+ }
+
+ special_char = known_locales.get(locale_encoding)
+ if special_char:
+ encoded_char = special_char.decode(locale_encoding)
+ temp_mod_name = 'test_imp_helper_' + encoded_char
+ test_package_name = 'test_imp_helper_package_' + encoded_char
+ init_file_name = os.path.join(test_package_name, '__init__.py')
+ try:
+ with open(temp_mod_name + '.py', 'w') as file:
+ file.write('a = 1\n')
+ file, filename, info = imp.find_module(temp_mod_name)
+ self.assertNotEquals(None, file)
+ self.assertTrue(filename[:-3].endswith(temp_mod_name))
+ self.assertEquals('.py', info[0])
+ self.assertEquals('U', info[1])
+ self.assertEquals(imp.PY_SOURCE, info[2])
+
+ mod = imp.load_module(temp_mod_name, file, filename, info)
+ self.assertEquals(1, mod.a)
+ file.close()
+
+ mod = imp.load_source(temp_mod_name, temp_mod_name + '.py')
+ self.assertEquals(1, mod.a)
+
+ mod = imp.load_compiled(temp_mod_name, temp_mod_name + '.pyc')
+ self.assertEquals(1, mod.a)
+
+ if not os.path.exists(test_package_name):
+ os.mkdir(test_package_name)
+ with open(init_file_name, 'w') as file:
+ file.write('b = 2\n')
+ package = imp.load_package(test_package_name, test_package_name)
+ self.assertEquals(2, package.b)
+ finally:
+ support.unlink(temp_mod_name + '.py')
+ support.unlink(temp_mod_name + '.pyc')
+ support.unlink(temp_mod_name + '.pyo')
+
+ support.unlink(init_file_name + '.py')
+ support.unlink(init_file_name + '.pyc')
+ support.unlink(init_file_name + '.pyo')
+ support.rmtree(test_package_name)
+
+
 def test_reload(self):
 import marshal
 imp.reload(marshal)
Modified: python/branches/py3k-short-float-repr/Lib/test/test_io.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_io.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_io.py	Sun Apr 5 01:04:14 2009
@@ -1754,6 +1754,13 @@
 self.assertEquals(f.read(), data * 2)
 self.assertEquals(buf.getvalue(), (data * 2).encode(encoding))
 
+ def test_unreadable(self):
+ class UnReadable(self.BytesIO):
+ def readable(self):
+ return False
+ txt = self.TextIOWrapper(UnReadable())
+ self.assertRaises(IOError, txt.read)
+
 def test_read_one_by_one(self):
 txt = self.TextIOWrapper(self.BytesIO(b"AA\r\nBB"))
 reads = ""
@@ -1989,13 +1996,13 @@
 def test___all__(self):
 for name in self.io.__all__:
 obj = getattr(self.io, name, None)
- self.assert_(obj is not None, name)
+ self.assertTrue(obj is not None, name)
 if name == "open":
 continue
 elif "error" in name.lower():
- self.assert_(issubclass(obj, Exception), name)
- else:
- self.assert_(issubclass(obj, self.IOBase), name)
+ self.assertTrue(issubclass(obj, Exception), name)
+ elif not name.startswith("SEEK_"):
+ self.assertTrue(issubclass(obj, self.IOBase))
 
 def test_attributes(self):
 f = self.open(support.TESTFN, "wb", buffering=0)
Modified: python/branches/py3k-short-float-repr/Lib/test/test_ioctl.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_ioctl.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_ioctl.py	Sun Apr 5 01:04:14 2009
@@ -1,12 +1,9 @@
 import unittest
-from test.support import run_unittest
+from test.support import run_unittest, import_module, get_attribute
 import os, struct
-try:
- import fcntl, termios
-except ImportError:
- raise unittest.SkipTest("No fcntl or termios module")
-if not hasattr(termios,'TIOCGPGRP'):
- raise unittest.SkipTest("termios module doesn't have TIOCGPGRP")
+fcntl = import_module('fcntl')
+termios = import_module('termios')
+get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature
 
 try:
 tty = open("/dev/tty", "r")
Modified: python/branches/py3k-short-float-repr/Lib/test/test_locale.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_locale.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_locale.py	Sun Apr 5 01:04:14 2009
@@ -219,6 +219,19 @@
 (self.sep, self.sep))
 
 
+class TestFormatPatternArg(unittest.TestCase):
+ # Test handling of pattern argument of format
+
+ def test_onlyOnePattern(self):
+ # Issue 2522: accept exactly one % pattern, and no extra chars.
+ self.assertRaises(ValueError, locale.format, "%f\n", 'foo')
+ self.assertRaises(ValueError, locale.format, "%f\r", 'foo')
+ self.assertRaises(ValueError, locale.format, "%f\r\n", 'foo')
+ self.assertRaises(ValueError, locale.format, " %f", 'foo')
+ self.assertRaises(ValueError, locale.format, "%fg", 'foo')
+ self.assertRaises(ValueError, locale.format, "%^g", 'foo')
+
+
 class TestNumberFormatting(BaseLocalizedTest, EnUSNumberFormatting):
 # Test number formatting with a real English locale.
 
@@ -314,6 +327,7 @@
 def test_main():
 tests = [
 TestMiscellaneous,
+ TestFormatPatternArg,
 TestEnUSNumberFormatting,
 TestCNumberFormatting,
 TestFrFRNumberFormatting,
Modified: python/branches/py3k-short-float-repr/Lib/test/test_logging.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_logging.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_logging.py	Sun Apr 5 01:04:14 2009
@@ -910,30 +910,32 @@
 
 
 class WarningsTest(BaseTest):
+
 def test_warnings(self):
 logging.captureWarnings(True)
- warnings.filterwarnings("always", category=UserWarning)
- try:
- file = io.StringIO()
- h = logging.StreamHandler(file)
- logger = logging.getLogger("py.warnings")
- logger.addHandler(h)
- warnings.warn("I'm warning you...")
- logger.removeHandler(h)
- s = file.getvalue()
- h.close()
- self.assertTrue(s.find("UserWarning: I'm warning you...\n") > 0)
-
- #See if an explicit file uses the original implementation
- file = io.StringIO()
- warnings.showwarning("Explicit", UserWarning, "dummy.py", 42, file,
- "Dummy line")
- s = file.getvalue()
- file.close()
- self.assertEqual(s, "dummy.py:42: UserWarning: Explicit\n Dummy line\n")
- finally:
- warnings.resetwarnings()
- logging.captureWarnings(False)
+ with warnings.catch_warnings():
+ warnings.filterwarnings("always", category=UserWarning)
+ try:
+ file = io.StringIO()
+ h = logging.StreamHandler(file)
+ logger = logging.getLogger("py.warnings")
+ logger.addHandler(h)
+ warnings.warn("I'm warning you...")
+ logger.removeHandler(h)
+ s = file.getvalue()
+ h.close()
+ self.assertTrue(s.find("UserWarning: I'm warning you...\n") > 0)
+
+ #See if an explicit file uses the original implementation
+ file = io.StringIO()
+ warnings.showwarning("Explicit", UserWarning, "dummy.py", 42,
+ file, "Dummy line")
+ s = file.getvalue()
+ file.close()
+ self.assertEqual(s,
+ "dummy.py:42: UserWarning: Explicit\n Dummy line\n")
+ finally:
+ logging.captureWarnings(False)
 
 # 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
Modified: python/branches/py3k-short-float-repr/Lib/test/test_mailbox.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_mailbox.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_mailbox.py	Sun Apr 5 01:04:14 2009
@@ -931,6 +931,12 @@
 self._box.remove(key1)
 self.assertEqual(self._box.get_sequences(), {'flagged':[key0]})
 
+ def test_issue2625(self):
+ msg0 = mailbox.MHMessage(self._template % 0)
+ msg0.add_sequence('foo')
+ key0 = self._box.add(msg0)
+ refmsg0 = self._box.get_message(key0)
+
 def test_pack(self):
 # Pack the contents of the mailbox
 msg0 = mailbox.MHMessage(self._template % 0)
Modified: python/branches/py3k-short-float-repr/Lib/test/test_mmap.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_mmap.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_mmap.py	Sun Apr 5 01:04:14 2009
@@ -1,7 +1,9 @@
-from test.support import TESTFN, run_unittest
-import mmap
+from test.support import TESTFN, run_unittest, import_module
 import unittest
-import os, re
+import os, re, itertools
+
+# Skip test if we can't import mmap.
+mmap = import_module('mmap')
 
 PAGESIZE = mmap.PAGESIZE
 
@@ -35,7 +37,7 @@
 # Simple sanity checks
 
 tp = str(type(m)) # SF bug 128713: segfaulted on Linux
- self.assertEqual(m.find('foo'), PAGESIZE)
+ self.assertEqual(m.find(b'foo'), PAGESIZE)
 
 self.assertEqual(len(m), 2*PAGESIZE)
 
@@ -260,38 +262,38 @@
 
 def test_find_end(self):
 # test the new 'end' parameter works as expected
- f = open(TESTFN, 'w+')
- data = 'one two ones'
+ f = open(TESTFN, 'wb+')
+ data = b'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)
+ self.assertEqual(m.find(b'one'), 0)
+ self.assertEqual(m.find(b'ones'), 8)
+ self.assertEqual(m.find(b'one', 0, -1), 0)
+ self.assertEqual(m.find(b'one', 1), 8)
+ self.assertEqual(m.find(b'one', 1, -1), 8)
+ self.assertEqual(m.find(b'one', 1, -2), -1)
 
 
 def test_rfind(self):
 # test the new 'end' parameter works as expected
- f = open(TESTFN, 'w+')
- data = 'one two ones'
+ f = open(TESTFN, 'wb+')
+ data = b'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)
+ self.assertEqual(m.rfind(b'one'), 8)
+ self.assertEqual(m.rfind(b'one '), 0)
+ self.assertEqual(m.rfind(b'one', 0, -1), 8)
+ self.assertEqual(m.rfind(b'one', 0, -2), 0)
+ self.assertEqual(m.rfind(b'one', 1, -1), 8)
+ self.assertEqual(m.rfind(b'one', 1, -2), -1)
 
 
 def test_double_close(self):
@@ -335,6 +337,35 @@
 mf.close()
 f.close()
 
+ # more excessive test
+ data = b"0123456789"
+ for dest in range(len(data)):
+ for src in range(len(data)):
+ for count in range(len(data) - max(dest, src)):
+ expected = data[:dest] + data[src:src+count] + data[dest+count:]
+ m = mmap.mmap(-1, len(data))
+ m[:] = data
+ m.move(dest, src, count)
+ self.assertEqual(m[:], expected)
+ m.close()
+
+ # segfault test (Issue 5387)
+ m = mmap.mmap(-1, 100)
+ offsets = [-100, -1, 0, 1, 100]
+ for source, dest, size in itertools.product(offsets, offsets, offsets):
+ try:
+ m.move(source, dest, size)
+ except ValueError:
+ pass
+ self.assertRaises(ValueError, m.move, -1, -1, -1)
+ self.assertRaises(ValueError, m.move, -1, -1, 0)
+ self.assertRaises(ValueError, m.move, -1, 0, -1)
+ self.assertRaises(ValueError, m.move, 0, -1, -1)
+ self.assertRaises(ValueError, m.move, -1, 0, 0)
+ self.assertRaises(ValueError, m.move, 0, -1, 0)
+ self.assertRaises(ValueError, m.move, 0, 0, -1)
+ m.close()
+
 def test_anonymous(self):
 # anonymous mmap.mmap(-1, PAGE)
 m = mmap.mmap(-1, PAGESIZE)
@@ -475,21 +506,15 @@
 # Test write_byte()
 for i in range(len(data)):
 self.assertEquals(m.tell(), i)
- m.write_byte(data[i:i+1])
+ m.write_byte(data[i])
 self.assertEquals(m.tell(), i+1)
- self.assertRaises(ValueError, m.write_byte, b"x")
+ self.assertRaises(ValueError, m.write_byte, b"x"[0])
 self.assertEquals(m[:], data)
 # Test read_byte()
 m.seek(0)
 for i in range(len(data)):
 self.assertEquals(m.tell(), i)
- # XXX: Disable this test for now because it's not clear
- # which type of object m.read_byte returns. Currently, it
- # returns 1-length str (unicode).
- if 0:
- self.assertEquals(m.read_byte(), data[i:i+1])
- else:
- m.read_byte()
+ self.assertEquals(m.read_byte(), data[i])
 self.assertEquals(m.tell(), i+1)
 self.assertRaises(ValueError, m.read_byte)
 # Test read()
Modified: python/branches/py3k-short-float-repr/Lib/test/test_multibytecodec.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_multibytecodec.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_multibytecodec.py	Sun Apr 5 01:04:14 2009
@@ -112,6 +112,10 @@
 self.assertRaises(UnicodeEncodeError, encoder.encode, '\u0123')
 self.assertEqual(encoder.encode('', True), b'\xa9\xdc')
 
+ def test_issue5640(self):
+ encoder = codecs.getincrementalencoder('shift-jis')('backslashreplace')
+ self.assertEqual(encoder.encode('\xff'), b'\\xff')
+ self.assertEqual(encoder.encode('\n'), b'\n')
 
 class Test_IncrementalDecoder(unittest.TestCase):
 
Modified: python/branches/py3k-short-float-repr/Lib/test/test_multiprocessing.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_multiprocessing.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_multiprocessing.py	Sun Apr 5 01:04:14 2009
@@ -17,20 +17,19 @@
 import socket
 import random
 import logging
+import test.support
 
 
-# Work around broken sem_open implementations
-try:
- import multiprocessing.synchronize
-except ImportError as e:
- raise unittest.SkipTest(e)
+# Skip tests if _multiprocessing wasn't built.
+_multiprocessing = test.support.import_module('_multiprocessing')
+# Skip tests if sem_open implementation is broken.
+test.support.import_module('multiprocessing.synchronize')
 
 import multiprocessing.dummy
 import multiprocessing.connection
 import multiprocessing.managers
 import multiprocessing.heap
 import multiprocessing.pool
-import _multiprocessing
 
 from multiprocessing import util
 
@@ -548,6 +547,10 @@
 self.assertEqual(lock.release(), None)
 self.assertRaises((AssertionError, RuntimeError), lock.release)
 
+ def test_lock_context(self):
+ with self.Lock():
+ pass
+
 
 class _TestSemaphore(BaseTestCase):
 
@@ -1209,10 +1212,12 @@
 p.start()
 queue = manager.get_queue()
 self.assertEqual(queue.get(), 'hello world')
+ del queue
 manager.shutdown()
 manager = QueueManager(
 address=('localhost', 9999), authkey=authkey, serializer=SERIALIZER)
 manager.start()
+ manager.shutdown()
 
 #
 #
Modified: python/branches/py3k-short-float-repr/Lib/test/test_nis.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_nis.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_nis.py	Sun Apr 5 01:04:14 2009
@@ -1,6 +1,8 @@
 from test import support
 import unittest
-import nis
+
+# Skip test if nis module does not exist.
+nis = support.import_module('nis')
 
 raise unittest.SkipTest("test_nis hangs on Solaris")
 
Modified: python/branches/py3k-short-float-repr/Lib/test/test_ossaudiodev.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_ossaudiodev.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_ossaudiodev.py	Sun Apr 5 01:04:14 2009
@@ -3,8 +3,9 @@
 
 from test.support import findfile
 
+ossaudiodev = support.import_module('ossaudiodev')
+
 import errno
-import ossaudiodev
 import sys
 import sunau
 import time
Modified: python/branches/py3k-short-float-repr/Lib/test/test_posix.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_posix.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_posix.py	Sun Apr 5 01:04:14 2009
@@ -1,11 +1,7 @@
 "Test posix functions"
 
 from test import support
-
-try:
- import posix
-except ImportError:
- raise unittest.SkipTest("posix is not available")
+posix = support.import_module('posix') #skip if not supported
 
 import time
 import os
@@ -13,6 +9,7 @@
 import shutil
 import unittest
 import warnings
+
 warnings.filterwarnings('ignore', '.* potential security risk .*',
 RuntimeWarning)
 
Modified: python/branches/py3k-short-float-repr/Lib/test/test_pty.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_pty.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_pty.py	Sun Apr 5 01:04:14 2009
@@ -1,6 +1,7 @@
+from test import support
+pty = support.import_module("pty") #skip if not supported
 import errno
 import fcntl
-import pty
 import os
 import sys
 import signal
Modified: python/branches/py3k-short-float-repr/Lib/test/test_pwd.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_pwd.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_pwd.py	Sun Apr 5 01:04:14 2009
@@ -1,7 +1,7 @@
 import unittest
 from test import support
 
-import pwd
+pwd = support.import_module('pwd')
 
 class PwdTest(unittest.TestCase):
 
Modified: python/branches/py3k-short-float-repr/Lib/test/test_resource.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_resource.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_resource.py	Sun Apr 5 01:04:14 2009
@@ -1,9 +1,9 @@
 import unittest
 from test import support
-
-import resource
 import time
 
+resource = support.import_module('resource')
+
 # This test is checking a few specific problem spots with the resource module.
 
 class ResourceTest(unittest.TestCase):
Modified: python/branches/py3k-short-float-repr/Lib/test/test_scope.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_scope.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_scope.py	Sun Apr 5 01:04:14 2009
@@ -618,7 +618,6 @@
 self.assertEqual(dec(), 0)
 
 def testNonLocalMethod(self):
-
 def f(x):
 class c:
 def inc(self):
@@ -630,13 +629,36 @@
 x -= 1
 return x
 return c()
-
 c = f(0)
 self.assertEqual(c.inc(), 1)
 self.assertEqual(c.inc(), 2)
 self.assertEqual(c.dec(), 1)
 self.assertEqual(c.dec(), 0)
 
+ def testGlobalInParallelNestedFunctions(self):
+ # A symbol table bug leaked the global statement from one
+ # function to other nested functions in the same block.
+ # This test verifies that a global statement in the first
+ # function does not affect the second function.
+ CODE = """def f():
+ y = 1
+ def g():
+ global y
+ return y
+ def h():
+ return y + 1
+ return g, h
+y = 9
+g, h = f()
+result9 = g()
+result2 = h()
+"""
+ local_ns = {}
+ global_ns = {}
+ exec(CODE, local_ns, global_ns)
+ self.assertEqual(2, global_ns["result2"])
+ self.assertEqual(9, global_ns["result9"])
+
 def testNonLocalClass(self):
 
 def f(x):
Modified: python/branches/py3k-short-float-repr/Lib/test/test_sqlite.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_sqlite.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_sqlite.py	Sun Apr 5 01:04:14 2009
@@ -1,10 +1,9 @@
 import unittest
-from test.support import run_unittest
+from test.support import run_unittest, import_module
+
+# Skip test if _sqlite3 module not installed
+import_module('_sqlite3')
 
-try:
- import _sqlite3
-except ImportError:
- raise unittest.SkipTest('no sqlite available')
 from sqlite3.test import (dbapi, types, userfunctions,
 factory, transactions, hooks, regression,
 dump)
Modified: python/branches/py3k-short-float-repr/Lib/test/test_startfile.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_startfile.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_startfile.py	Sun Apr 5 01:04:14 2009
@@ -9,9 +9,11 @@
 
 import unittest
 from test import support
+import os
+from os import path
+
+startfile = support.get_attribute(os, 'startfile')
 
-# use this form so that the test is skipped when startfile is not available:
-from os import startfile, path
 
 class TestCase(unittest.TestCase):
 def test_nonexisting(self):
Modified: python/branches/py3k-short-float-repr/Lib/test/test_struct.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_struct.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_struct.py	Sun Apr 5 01:04:14 2009
@@ -207,6 +207,7 @@
 class IntTester(unittest.TestCase):
 
 def __init__(self, formatpair, bytesize):
+ super(IntTester, self).__init__(methodName='test_one')
 self.assertEqual(len(formatpair), 2)
 self.formatpair = formatpair
 for direction in "<>!=":
Modified: python/branches/py3k-short-float-repr/Lib/test/test_sundry.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_sundry.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_sundry.py	Sun Apr 5 01:04:14 2009
@@ -8,6 +8,7 @@
 class TestUntestedModules(unittest.TestCase):
 def test_at_least_import_untested_modules(self):
 with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
 import aifc
 import bdb
 import cgitb
Modified: python/branches/py3k-short-float-repr/Lib/test/test_symtable.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_symtable.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_symtable.py	Sun Apr 5 01:04:14 2009
@@ -88,7 +88,9 @@
 
 def test_globals(self):
 self.assertTrue(self.spam.lookup("glob").is_global())
+ self.assertFalse(self.spam.lookup("glob").is_declared_global())
 self.assertTrue(self.spam.lookup("bar").is_global())
+ self.assertTrue(self.spam.lookup("bar").is_declared_global())
 self.assertFalse(self.internal.lookup("x").is_global())
 self.assertFalse(self.Mine.lookup("instance_var").is_global())
 
Modified: python/branches/py3k-short-float-repr/Lib/test/test_sys.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_sys.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_sys.py	Sun Apr 5 01:04:14 2009
@@ -177,6 +177,9 @@
 def test_recursionlimit_fatalerror(self):
 # A fatal error occurs if a second recursion limit is hit when recovering
 # from a first one.
+ if os.name == "nt":
+ raise unittest.SkipTest(
+ "under Windows, test would generate a spurious crash dialog")
 code = textwrap.dedent("""
 import sys
 
Modified: python/branches/py3k-short-float-repr/Lib/test/test_syslog.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_syslog.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_syslog.py	Sun Apr 5 01:04:14 2009
@@ -1,7 +1,7 @@
 
-import syslog
-import unittest
 from test import support
+syslog = support.import_module("syslog") #skip if not supported
+import unittest
 
 # XXX(nnorwitz): This test sucks. I don't know of a platform independent way
 # to verify that the messages were really logged.
Modified: python/branches/py3k-short-float-repr/Lib/test/test_tcl.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_tcl.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_tcl.py	Sun Apr 5 01:04:14 2009
@@ -2,8 +2,11 @@
 
 import unittest
 import os
-import _tkinter
 from test import support
+
+# Skip this test if the _tkinter module wasn't built.
+_tkinter = support.import_module('_tkinter')
+
 from tkinter import Tcl
 from _tkinter import TclError
 
Modified: python/branches/py3k-short-float-repr/Lib/test/test_time.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_time.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_time.py	Sun Apr 5 01:04:14 2009
@@ -116,6 +116,11 @@
 self.fail("conversion specifier %r failed with '%s' input." %
 (format, strf_output))
 
+ def test_strptime_bytes(self):
+ # Make sure only strings are accepted as arguments to strptime.
+ self.assertRaises(TypeError, time.strptime, b'2009', "%Y")
+ self.assertRaises(TypeError, time.strptime, '2009', b'%Y')
+
 def test_asctime(self):
 time.asctime(time.gmtime(self.t))
 self.assertRaises(TypeError, time.asctime, 0)
Modified: python/branches/py3k-short-float-repr/Lib/test/test_tk.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_tk.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_tk.py	Sun Apr 5 01:04:14 2009
@@ -1,6 +1,9 @@
+from test import support
+# Skip test if _tkinter wasn't built.
+support.import_module('_tkinter')
+
 import tkinter
 from tkinter.test import runtktests
-from test import support
 import unittest
 
 try:
Modified: python/branches/py3k-short-float-repr/Lib/test/test_ttk_guionly.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_ttk_guionly.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_ttk_guionly.py	Sun Apr 5 01:04:14 2009
@@ -1,11 +1,15 @@
 import os
 import sys
-from tkinter import ttk
-from tkinter.test import runtktests
 import unittest
-from _tkinter import TclError
 from test import support
 
+# Skip this test if _tkinter wasn't built.
+support.import_module('_tkinter')
+
+from _tkinter import TclError
+from tkinter import ttk
+from tkinter.test import runtktests
+
 try:
 ttk.Button()
 except TclError as msg:
Modified: python/branches/py3k-short-float-repr/Lib/test/test_ttk_textonly.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_ttk_textonly.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_ttk_textonly.py	Sun Apr 5 01:04:14 2009
@@ -1,6 +1,10 @@
 import os
 import sys
 from test import support
+
+# Skip this test if _tkinter does not exist.
+support.import_module('_tkinter')
+
 from tkinter.test import runtktests
 
 def test_main():
Modified: python/branches/py3k-short-float-repr/Lib/test/test_types.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_types.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_types.py	Sun Apr 5 01:04:14 2009
@@ -341,6 +341,15 @@
 test(123456, "#012X", '0X000001E240')
 test(-123456, "#012X", '-0X00001E240')
 
+ test(123, ',', '123')
+ test(-123, ',', '-123')
+ test(1234, ',', '1,234')
+ test(-1234, ',', '-1,234')
+ test(123456, ',', '123,456')
+ test(-123456, ',', '-123,456')
+ test(1234567, ',', '1,234,567')
+ test(-1234567, ',', '-1,234,567')
+
 # make sure these are errors
 
 # precision disallowed
@@ -350,6 +359,8 @@
 # format spec must be string
 self.assertRaises(TypeError, 3 .__format__, None)
 self.assertRaises(TypeError, 3 .__format__, 0)
+ # can't have ',' with 'n'
+ self.assertRaises(ValueError, 3 .__format__, ",n")
 
 # ensure that only int and float type specifiers work
 for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] +
Modified: python/branches/py3k-short-float-repr/Lib/test/test_unittest.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_unittest.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_unittest.py	Sun Apr 5 01:04:14 2009
@@ -6,10 +6,12 @@
 TestCase.{assert,fail}* methods (some are tested implicitly)
 """
 
+import re
 from test import support
 import unittest
 from unittest import TestCase
 import types
+from copy import deepcopy
 
 ### Support code
 ################################################################
@@ -53,6 +55,8 @@
 
 
 class TestEquality(object):
+ """Used as a mixin for TestCase"""
+
 # Check for a valid __eq__ implementation
 def test_eq(self):
 for obj_1, obj_2 in self.eq_pairs:
@@ -66,25 +70,26 @@
 self.failIfEqual(obj_2, obj_1)
 
 class TestHashing(object):
+ """Used as a mixin for TestCase"""
+
 # Check for a valid __hash__ implementation
 def test_hash(self):
 for obj_1, obj_2 in self.eq_pairs:
 try:
- assert hash(obj_1) == hash(obj_2)
+ if not hash(obj_1) == hash(obj_2):
+ self.fail("%r and %r do not hash equal" % (obj_1, obj_2))
 except KeyboardInterrupt:
 raise
- except AssertionError:
- self.fail("%s and %s do not hash equal" % (obj_1, obj_2))
 except Exception as e:
- self.fail("Problem hashing %s and %s: %s" % (obj_1, obj_2, e))
+ self.fail("Problem hashing %r and %r: %s" % (obj_1, obj_2, e))
 
 for obj_1, obj_2 in self.ne_pairs:
 try:
- assert hash(obj_1) != hash(obj_2)
+ if hash(obj_1) == hash(obj_2):
+ self.fail("%s and %s hash equal, but shouldn't" %
+ (obj_1, obj_2))
 except KeyboardInterrupt:
 raise
- except AssertionError:
- self.fail("%s and %s hash equal, but shouldn't" % (obj_1, obj_2))
 except Exception as e:
 self.fail("Problem hashing %s and %s: %s" % (obj_1, obj_2, e))
 
@@ -2247,39 +2252,6 @@
 
 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
- # the first line of the test method's docstring, if available, or None."
- def test_shortDescription__no_docstring(self):
- class Foo(unittest.TestCase):
- def runTest(self):
- pass
-
- self.assertEqual(Foo().shortDescription(), None)
-
- # "Returns a one-line description of the test, or None if no description
- # has been provided. The default implementation of this method returns
- # the first line of the test method's docstring, if available, or None."
- def test_shortDescription__singleline_docstring(self):
- class Foo(unittest.TestCase):
- def runTest(self):
- "this tests foo"
- pass
-
- self.assertEqual(Foo().shortDescription(), "this tests foo")
-
- # "Returns a one-line description of the test, or None if no description
- # has been provided. The default implementation of this method returns
- # the first line of the test method's docstring, if available, or None."
- def test_shortDescription__multiline_docstring(self):
- class Foo(unittest.TestCase):
- def runTest(self):
- """this tests foo
- blah, bar and baz are also tested"""
- pass
-
- self.assertEqual(Foo().shortDescription(), "this tests foo")
-
 # "If result is omitted or None, a temporary result object is created
 # and used, but is not made available to the caller"
 def test_run__uses_defaultTestResult(self):
@@ -2298,6 +2270,408 @@
 expected = ['startTest', 'test', 'addSuccess', 'stopTest']
 self.assertEqual(events, expected)
 
+ def testShortDescriptionWithoutDocstring(self):
+ self.assertEqual(
+ self.shortDescription(),
+ 'testShortDescriptionWithoutDocstring (' + __name__ +
+ '.Test_TestCase)')
+
+ def testShortDescriptionWithOneLineDocstring(self):
+ """Tests shortDescription() for a method with a docstring."""
+ self.assertEqual(
+ self.shortDescription(),
+ ('testShortDescriptionWithOneLineDocstring '
+ '(' + __name__ + '.Test_TestCase)\n'
+ 'Tests shortDescription() for a method with a docstring.'))
+
+ def testShortDescriptionWithMultiLineDocstring(self):
+ """Tests shortDescription() for a method with a longer docstring.
+
+ This method ensures that only the first line of a docstring is
+ returned used in the short description, no matter how long the
+ whole thing is.
+ """
+ self.assertEqual(
+ self.shortDescription(),
+ ('testShortDescriptionWithMultiLineDocstring '
+ '(' + __name__ + '.Test_TestCase)\n'
+ 'Tests shortDescription() for a method with a longer '
+ 'docstring.'))
+
+ def testAddTypeEqualityFunc(self):
+ class SadSnake(object):
+ """Dummy class for test_addTypeEqualityFunc."""
+ s1, s2 = SadSnake(), SadSnake()
+ self.assertFalse(s1 == s2)
+ def AllSnakesCreatedEqual(a, b, msg=None):
+ return type(a) == type(b) == SadSnake
+ self.addTypeEqualityFunc(SadSnake, AllSnakesCreatedEqual)
+ self.assertEqual(s1, s2)
+ # No this doesn't clean up and remove the SadSnake equality func
+ # from this TestCase instance but since its a local nothing else
+ # will ever notice that.
+
+ def testAssertIn(self):
+ animals = {'monkey': 'banana', 'cow': 'grass', 'seal': 'fish'}
+
+ self.assertIn('a', 'abc')
+ self.assertIn(2, [1, 2, 3])
+ self.assertIn('monkey', animals)
+
+ self.assertNotIn('d', 'abc')
+ self.assertNotIn(0, [1, 2, 3])
+ self.assertNotIn('otter', animals)
+
+ self.assertRaises(self.failureException, self.assertIn, 'x', 'abc')
+ self.assertRaises(self.failureException, self.assertIn, 4, [1, 2, 3])
+ self.assertRaises(self.failureException, self.assertIn, 'elephant',
+ animals)
+
+ self.assertRaises(self.failureException, self.assertNotIn, 'c', 'abc')
+ self.assertRaises(self.failureException, self.assertNotIn, 1, [1, 2, 3])
+ self.assertRaises(self.failureException, self.assertNotIn, 'cow',
+ animals)
+
+ def testAssertDictContainsSubset(self):
+ self.assertDictContainsSubset({}, {})
+ self.assertDictContainsSubset({}, {'a': 1})
+ self.assertDictContainsSubset({'a': 1}, {'a': 1})
+ self.assertDictContainsSubset({'a': 1}, {'a': 1, 'b': 2})
+ self.assertDictContainsSubset({'a': 1, 'b': 2}, {'a': 1, 'b': 2})
+
+ self.assertRaises(unittest.TestCase.failureException,
+ self.assertDictContainsSubset, {'a': 2}, {'a': 1},
+ '.*Mismatched values:.*')
+
+ self.assertRaises(unittest.TestCase.failureException,
+ self.assertDictContainsSubset, {'c': 1}, {'a': 1},
+ '.*Missing:.*')
+
+ self.assertRaises(unittest.TestCase.failureException,
+ self.assertDictContainsSubset, {'a': 1, 'c': 1},
+ {'a': 1}, '.*Missing:.*')
+
+ self.assertRaises(unittest.TestCase.failureException,
+ self.assertDictContainsSubset, {'a': 1, 'c': 1},
+ {'a': 1}, '.*Missing:.*Mismatched values:.*')
+
+ def testAssertEqual(self):
+ equal_pairs = [
+ ((), ()),
+ ({}, {}),
+ ([], []),
+ (set(), set()),
+ (frozenset(), frozenset())]
+ for a, b in equal_pairs:
+ # This mess of try excepts is to test the assertEqual behavior
+ # itself.
+ try:
+ self.assertEqual(a, b)
+ except self.failureException:
+ self.fail('assertEqual(%r, %r) failed' % (a, b))
+ try:
+ self.assertEqual(a, b, msg='foo')
+ except self.failureException:
+ self.fail('assertEqual(%r, %r) with msg= failed' % (a, b))
+ try:
+ self.assertEqual(a, b, 'foo')
+ except self.failureException:
+ self.fail('assertEqual(%r, %r) with third parameter failed' %
+ (a, b))
+
+ unequal_pairs = [
+ ((), []),
+ ({}, set()),
+ (set([4,1]), frozenset([4,2])),
+ (frozenset([4,5]), set([2,3])),
+ (set([3,4]), set([5,4]))]
+ for a, b in unequal_pairs:
+ self.assertRaises(self.failureException, self.assertEqual, a, b)
+ self.assertRaises(self.failureException, self.assertEqual, a, b,
+ 'foo')
+ self.assertRaises(self.failureException, self.assertEqual, a, b,
+ msg='foo')
+
+ def testEquality(self):
+ self.assertListEqual([], [])
+ self.assertTupleEqual((), ())
+ self.assertSequenceEqual([], ())
+
+ a = [0, 'a', []]
+ b = []
+ self.assertRaises(unittest.TestCase.failureException,
+ self.assertListEqual, a, b)
+ self.assertRaises(unittest.TestCase.failureException,
+ self.assertListEqual, tuple(a), tuple(b))
+ self.assertRaises(unittest.TestCase.failureException,
+ self.assertSequenceEqual, a, tuple(b))
+
+ b.extend(a)
+ self.assertListEqual(a, b)
+ self.assertTupleEqual(tuple(a), tuple(b))
+ self.assertSequenceEqual(a, tuple(b))
+ self.assertSequenceEqual(tuple(a), b)
+
+ self.assertRaises(self.failureException, self.assertListEqual,
+ a, tuple(b))
+ self.assertRaises(self.failureException, self.assertTupleEqual,
+ tuple(a), b)
+ self.assertRaises(self.failureException, self.assertListEqual, None, b)
+ self.assertRaises(self.failureException, self.assertTupleEqual, None,
+ tuple(b))
+ self.assertRaises(self.failureException, self.assertSequenceEqual,
+ None, tuple(b))
+ self.assertRaises(self.failureException, self.assertListEqual, 1, 1)
+ self.assertRaises(self.failureException, self.assertTupleEqual, 1, 1)
+ self.assertRaises(self.failureException, self.assertSequenceEqual,
+ 1, 1)
+
+ self.assertDictEqual({}, {})
+
+ c = { 'x': 1 }
+ d = {}
+ self.assertRaises(unittest.TestCase.failureException,
+ self.assertDictEqual, c, d)
+
+ d.update(c)
+ self.assertDictEqual(c, d)
+
+ d['x'] = 0
+ self.assertRaises(unittest.TestCase.failureException,
+ self.assertDictEqual, c, d, 'These are unequal')
+
+ self.assertRaises(self.failureException, self.assertDictEqual, None, d)
+ self.assertRaises(self.failureException, self.assertDictEqual, [], d)
+ self.assertRaises(self.failureException, self.assertDictEqual, 1, 1)
+
+ self.assertSameElements([1, 2, 3], [3, 2, 1])
+ self.assertSameElements([1, 2] + [3] * 100, [1] * 100 + [2, 3])
+ self.assertSameElements(['foo', 'bar', 'baz'], ['bar', 'baz', 'foo'])
+ self.assertRaises(self.failureException, self.assertSameElements,
+ [10], [10, 11])
+ self.assertRaises(self.failureException, self.assertSameElements,
+ [10, 11], [10])
+
+ # Test that sequences of unhashable objects can be tested for sameness:
+ self.assertSameElements([[1, 2], [3, 4]], [[3, 4], [1, 2]])
+ self.assertSameElements([{'a': 1}, {'b': 2}], [{'b': 2}, {'a': 1}])
+ self.assertRaises(self.failureException, self.assertSameElements,
+ [[1]], [[2]])
+ self.assertRaises(self.failureException, self.assertSameElements,
+ [{'a': 1}, {'b': 2}], [{'b': 2}, {'a': 2}])
+
+ def testAssertSetEqual(self):
+ set1 = set()
+ set2 = set()
+ self.assertSetEqual(set1, set2)
+
+ self.assertRaises(self.failureException, self.assertSetEqual, None, set2)
+ self.assertRaises(self.failureException, self.assertSetEqual, [], set2)
+ self.assertRaises(self.failureException, self.assertSetEqual, set1, None)
+ self.assertRaises(self.failureException, self.assertSetEqual, set1, [])
+
+ set1 = set(['a'])
+ set2 = set()
+ self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)
+
+ set1 = set(['a'])
+ set2 = set(['a'])
+ self.assertSetEqual(set1, set2)
+
+ set1 = set(['a'])
+ set2 = set(['a', 'b'])
+ self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)
+
+ set1 = set(['a'])
+ set2 = frozenset(['a', 'b'])
+ self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)
+
+ set1 = set(['a', 'b'])
+ set2 = frozenset(['a', 'b'])
+ self.assertSetEqual(set1, set2)
+
+ set1 = set()
+ set2 = "foo"
+ self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)
+ self.assertRaises(self.failureException, self.assertSetEqual, set2, set1)
+
+ # make sure any string formatting is tuple-safe
+ set1 = set([(0, 1), (2, 3)])
+ set2 = set([(4, 5)])
+ self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)
+
+ def testInequality(self):
+ # Try ints
+ self.assertGreater(2, 1)
+ self.assertGreaterEqual(2, 1)
+ self.assertGreaterEqual(1, 1)
+ self.assertLess(1, 2)
+ self.assertLessEqual(1, 2)
+ self.assertLessEqual(1, 1)
+ self.assertRaises(self.failureException, self.assertGreater, 1, 2)
+ self.assertRaises(self.failureException, self.assertGreater, 1, 1)
+ self.assertRaises(self.failureException, self.assertGreaterEqual, 1, 2)
+ self.assertRaises(self.failureException, self.assertLess, 2, 1)
+ self.assertRaises(self.failureException, self.assertLess, 1, 1)
+ self.assertRaises(self.failureException, self.assertLessEqual, 2, 1)
+
+ # Try Floats
+ self.assertGreater(1.1, 1.0)
+ self.assertGreaterEqual(1.1, 1.0)
+ self.assertGreaterEqual(1.0, 1.0)
+ self.assertLess(1.0, 1.1)
+ self.assertLessEqual(1.0, 1.1)
+ self.assertLessEqual(1.0, 1.0)
+ self.assertRaises(self.failureException, self.assertGreater, 1.0, 1.1)
+ self.assertRaises(self.failureException, self.assertGreater, 1.0, 1.0)
+ self.assertRaises(self.failureException, self.assertGreaterEqual, 1.0, 1.1)
+ self.assertRaises(self.failureException, self.assertLess, 1.1, 1.0)
+ self.assertRaises(self.failureException, self.assertLess, 1.0, 1.0)
+ self.assertRaises(self.failureException, self.assertLessEqual, 1.1, 1.0)
+
+ # Try Strings
+ self.assertGreater('bug', 'ant')
+ self.assertGreaterEqual('bug', 'ant')
+ self.assertGreaterEqual('ant', 'ant')
+ self.assertLess('ant', 'bug')
+ self.assertLessEqual('ant', 'bug')
+ self.assertLessEqual('ant', 'ant')
+ self.assertRaises(self.failureException, self.assertGreater, 'ant', 'bug')
+ self.assertRaises(self.failureException, self.assertGreater, 'ant', 'ant')
+ self.assertRaises(self.failureException, self.assertGreaterEqual, 'ant', 'bug')
+ self.assertRaises(self.failureException, self.assertLess, 'bug', 'ant')
+ self.assertRaises(self.failureException, self.assertLess, 'ant', 'ant')
+ self.assertRaises(self.failureException, self.assertLessEqual, 'bug', 'ant')
+
+ # Try bytes
+ self.assertGreater(b'bug', b'ant')
+ self.assertGreaterEqual(b'bug', b'ant')
+ self.assertGreaterEqual(b'ant', b'ant')
+ self.assertLess(b'ant', b'bug')
+ self.assertLessEqual(b'ant', b'bug')
+ self.assertLessEqual(b'ant', b'ant')
+ self.assertRaises(self.failureException, self.assertGreater, b'ant', b'bug')
+ self.assertRaises(self.failureException, self.assertGreater, b'ant', b'ant')
+ self.assertRaises(self.failureException, self.assertGreaterEqual, b'ant',
+ b'bug')
+ self.assertRaises(self.failureException, self.assertLess, b'bug', b'ant')
+ self.assertRaises(self.failureException, self.assertLess, b'ant', b'ant')
+ self.assertRaises(self.failureException, self.assertLessEqual, b'bug', b'ant')
+
+ def testAssertMultiLineEqual(self):
+ sample_text = """\
+http://www.python.org/doc/2.3/lib/module-unittest.html
+test case
+ A test case is the smallest unit of testing. [...]
+"""
+ revised_sample_text = """\
+http://www.python.org/doc/2.4.1/lib/module-unittest.html
+test case
+ A test case is the smallest unit of testing. [...] You may provide your
+ own implementation that does not subclass from TestCase, of course.
+"""
+ sample_text_error = """
+- http://www.python.org/doc/2.3/lib/module-unittest.html
+? ^
++ http://www.python.org/doc/2.4.1/lib/module-unittest.html
+? ^^^
+ test case
+- A test case is the smallest unit of testing. [...]
++ A test case is the smallest unit of testing. [...] You may provide your
+? +++++++++++++++++++++
++ own implementation that does not subclass from TestCase, of course.
+"""
+
+ try:
+ self.assertMultiLineEqual(sample_text, revised_sample_text)
+ except self.failureException as e:
+ # no fair testing ourself with ourself, use assertEqual..
+ self.assertEqual(sample_text_error, str(e))
+
+ def testAssertIsNone(self):
+ self.assertIsNone(None)
+ self.assertRaises(self.failureException, self.assertIsNone, False)
+ self.assertIsNotNone('DjZoPloGears on Rails')
+ self.assertRaises(self.failureException, self.assertIsNotNone, None)
+
+ def testAssertRegexpMatches(self):
+ self.assertRegexpMatches('asdfabasdf', r'ab+')
+ self.assertRaises(self.failureException, self.assertRegexpMatches,
+ 'saaas', r'aaaa')
+
+ def testAssertRaisesRegexp(self):
+ class ExceptionMock(Exception):
+ pass
+
+ def Stub():
+ raise ExceptionMock('We expect')
+
+ self.assertRaisesRegexp(ExceptionMock, re.compile('expect$'), Stub)
+ self.assertRaisesRegexp(ExceptionMock, 'expect$', Stub)
+
+ def testAssertNotRaisesRegexp(self):
+ self.assertRaisesRegexp(
+ self.failureException, '^Exception not raised by <lambda>$',
+ self.assertRaisesRegexp, Exception, re.compile('x'),
+ lambda: None)
+ self.assertRaisesRegexp(
+ self.failureException, '^Exception not raised by <lambda>$',
+ self.assertRaisesRegexp, Exception, 'x',
+ lambda: None)
+
+ def testAssertRaisesRegexpMismatch(self):
+ def Stub():
+ raise Exception('Unexpected')
+
+ self.assertRaisesRegexp(
+ self.failureException,
+ r'"\^Expected\$" does not match "Unexpected"',
+ self.assertRaisesRegexp, Exception, '^Expected$',
+ Stub)
+ self.assertRaisesRegexp(
+ self.failureException,
+ r'"\^Expected\$" does not match "Unexpected"',
+ self.assertRaisesRegexp, Exception,
+ re.compile('^Expected$'), Stub)
+
+ def testSynonymAssertMethodNames(self):
+ """Test undocumented method name synonyms.
+
+ Please do not use these methods names in your own code.
+
+ This test confirms their continued existence and functionality
+ in order to avoid breaking existing code.
+ """
+ self.assertNotEquals(3, 5)
+ self.assertEquals(3, 3)
+ self.assertAlmostEquals(2.0, 2.0)
+ self.assertNotAlmostEquals(3.0, 5.0)
+ self.assert_(True)
+
+ def testPendingDeprecationMethodNames(self):
+ """Test fail* methods pending deprecation, they will warn in 3.2.
+
+ Do not use these methods. They will go away in 3.3.
+ """
+ self.failIfEqual(3, 5)
+ self.failUnlessEqual(3, 3)
+ self.failUnlessAlmostEqual(2.0, 2.0)
+ self.failIfAlmostEqual(3.0, 5.0)
+ self.failUnless(True)
+ self.failUnlessRaises(TypeError, lambda _: 3.14 + 'spam')
+ self.failIf(False)
+
+ def testDeepcopy(self):
+ # Issue: 5660
+ class TestableTest(TestCase):
+ def testNothing(self):
+ pass
+
+ test = TestableTest('testNothing')
+
+ # This shouldn't blow up
+ deepcopy(test)
+
 
 class Test_TestSkipping(TestCase):
 
@@ -2396,20 +2770,20 @@
 def test_AlmostEqual(self):
 self.failUnlessAlmostEqual(1.00000001, 1.0)
 self.failIfAlmostEqual(1.0000001, 1.0)
- self.assertRaises(AssertionError,
+ self.assertRaises(self.failureException,
 self.failUnlessAlmostEqual, 1.0000001, 1.0)
- self.assertRaises(AssertionError,
+ self.assertRaises(self.failureException,
 self.failIfAlmostEqual, 1.00000001, 1.0)
 
 self.failUnlessAlmostEqual(1.1, 1.0, places=0)
- self.assertRaises(AssertionError,
+ self.assertRaises(self.failureException,
 self.failUnlessAlmostEqual, 1.1, 1.0, places=1)
 
 self.failUnlessAlmostEqual(0, .1+.1j, places=0)
 self.failIfAlmostEqual(0, .1+.1j, places=1)
- self.assertRaises(AssertionError,
+ self.assertRaises(self.failureException,
 self.failUnlessAlmostEqual, 0, .1+.1j, places=1)
- self.assertRaises(AssertionError,
+ self.assertRaises(self.failureException,
 self.failIfAlmostEqual, 0, .1+.1j, places=0)
 
 def test_assertRaises(self):
@@ -2419,7 +2793,7 @@
 self.assertRaises(KeyError, _raise, KeyError("key"))
 try:
 self.assertRaises(KeyError, lambda: None)
- except AssertionError as e:
+ except self.failureException as e:
 self.assert_("KeyError not raised" in str(e), str(e))
 else:
 self.fail("assertRaises() didn't fail")
@@ -2436,7 +2810,7 @@
 try:
 with self.assertRaises(KeyError):
 pass
- except AssertionError as e:
+ except self.failureException as e:
 self.assert_("KeyError not raised" in str(e), str(e))
 else:
 self.fail("assertRaises() didn't fail")
@@ -2449,6 +2823,172 @@
 self.fail("assertRaises() didn't let exception pass through")
 
 
+class TestLongMessage(TestCase):
+ """Test that the individual asserts honour longMessage.
+ This actually tests all the message behaviour for
+ asserts that use longMessage."""
+
+ def setUp(self):
+ class TestableTestFalse(TestCase):
+ longMessage = False
+ failureException = self.failureException
+
+ def testTest(self):
+ pass
+
+ class TestableTestTrue(TestCase):
+ longMessage = True
+ failureException = self.failureException
+
+ def testTest(self):
+ pass
+
+ self.testableTrue = TestableTestTrue('testTest')
+ self.testableFalse = TestableTestFalse('testTest')
+
+ def testDefault(self):
+ self.assertFalse(TestCase.longMessage)
+
+ def test_formatMsg(self):
+ self.assertEquals(self.testableFalse._formatMessage(None, "foo"), "foo")
+ self.assertEquals(self.testableFalse._formatMessage("foo", "bar"), "foo")
+
+ self.assertEquals(self.testableTrue._formatMessage(None, "foo"), "foo")
+ self.assertEquals(self.testableTrue._formatMessage("foo", "bar"), "bar : foo")
+
+ def assertMessages(self, methodName, args, errors):
+ def getMethod(i):
+ useTestableFalse = i < 2
+ if useTestableFalse:
+ test = self.testableFalse
+ else:
+ test = self.testableTrue
+ return getattr(test, methodName)
+
+ for i, expected_regexp in enumerate(errors):
+ testMethod = getMethod(i)
+ kwargs = {}
+ withMsg = i % 2
+ if withMsg:
+ kwargs = {"msg": "oops"}
+
+ with self.assertRaisesRegexp(self.failureException,
+ expected_regexp=expected_regexp):
+ testMethod(*args, **kwargs)
+
+ def testAssertTrue(self):
+ self.assertMessages('assertTrue', (False,),
+ ["^False is not True$", "^oops$", "^False is not True$",
+ "^False is not True : oops$"])
+
+ def testAssertFalse(self):
+ self.assertMessages('assertFalse', (True,),
+ ["^True is not False$", "^oops$", "^True is not False$",
+ "^True is not False : oops$"])
+
+ def testNotEqual(self):
+ self.assertMessages('assertNotEqual', (1, 1),
+ ["^1 == 1$", "^oops$", "^1 == 1$",
+ "^1 == 1 : oops$"])
+
+ def testAlmostEqual(self):
+ self.assertMessages('assertAlmostEqual', (1, 2),
+ ["^1 != 2 within 7 places$", "^oops$",
+ "^1 != 2 within 7 places$", "^1 != 2 within 7 places : oops$"])
+
+ def testNotAlmostEqual(self):
+ self.assertMessages('assertNotAlmostEqual', (1, 1),
+ ["^1 == 1 within 7 places$", "^oops$",
+ "^1 == 1 within 7 places$", "^1 == 1 within 7 places : oops$"])
+
+ def test_baseAssertEqual(self):
+ self.assertMessages('_baseAssertEqual', (1, 2),
+ ["^1 != 2$", "^oops$", "^1 != 2$", "^1 != 2 : oops$"])
+
+ def testAssertSequenceEqual(self):
+ # Error messages are multiline so not testing on full message
+ # assertTupleEqual and assertListEqual delegate to this method
+ self.assertMessages('assertSequenceEqual', ([], [None]),
+ ["\+ \[None\]$", "^oops$", r"\+ \[None\]$",
+ r"\+ \[None\] : oops$"])
+
+ def testAssertSetEqual(self):
+ self.assertMessages('assertSetEqual', (set(), set([None])),
+ ["None$", "^oops$", "None$",
+ "None : oops$"])
+
+ def testAssertIn(self):
+ self.assertMessages('assertIn', (None, []),
+ ['^None not found in \[\]$', "^oops$",
+ '^None not found in \[\]$',
+ '^None not found in \[\] : oops$'])
+
+ def testAssertNotIn(self):
+ self.assertMessages('assertNotIn', (None, [None]),
+ ['^None unexpectedly found in \[None\]$', "^oops$",
+ '^None unexpectedly found in \[None\]$',
+ '^None unexpectedly found in \[None\] : oops$'])
+
+ def testAssertDictEqual(self):
+ self.assertMessages('assertDictEqual', ({}, {'key': 'value'}),
+ [r"\+ \{'key': 'value'\}$", "^oops$",
+ "\+ \{'key': 'value'\}$",
+ "\+ \{'key': 'value'\} : oops$"])
+
+ def testAssertDictContainsSubset(self):
+ self.assertMessages('assertDictContainsSubset', ({'key': 'value'}, {}),
+ ["^Missing: 'key'$", "^oops$",
+ "^Missing: 'key'$",
+ "^Missing: 'key' : oops$"])
+
+ def testAssertSameElements(self):
+ self.assertMessages('assertSameElements', ([], [None]),
+ [r"\[None\]$", "^oops$",
+ r"\[None\]$",
+ r"\[None\] : oops$"])
+
+ def testAssertMultiLineEqual(self):
+ self.assertMessages('assertMultiLineEqual', ("", "foo"),
+ [r"\+ foo$", "^oops$",
+ r"\+ foo$",
+ r"\+ foo : oops$"])
+
+ def testAssertLess(self):
+ self.assertMessages('assertLess', (2, 1),
+ ["^2 not less than 1$", "^oops$",
+ "^2 not less than 1$", "^2 not less than 1 : oops$"])
+
+ def testAssertLessEqual(self):
+ self.assertMessages('assertLessEqual', (2, 1),
+ ["^2 not less than or equal to 1$", "^oops$",
+ "^2 not less than or equal to 1$",
+ "^2 not less than or equal to 1 : oops$"])
+
+ def testAssertGreater(self):
+ self.assertMessages('assertGreater', (1, 2),
+ ["^1 not greater than 2$", "^oops$",
+ "^1 not greater than 2$",
+ "^1 not greater than 2 : oops$"])
+
+ def testAssertGreaterEqual(self):
+ self.assertMessages('assertGreaterEqual', (1, 2),
+ ["^1 not greater than or equal to 2$", "^oops$",
+ "^1 not greater than or equal to 2$",
+ "^1 not greater than or equal to 2 : oops$"])
+
+ def testAssertIsNone(self):
+ self.assertMessages('assertIsNone', ('not None',),
+ ["^'not None' is not None$", "^oops$",
+ "^'not None' is not None$",
+ "^'not None' is not None : oops$"])
+
+ def testAssertIsNotNone(self):
+ self.assertMessages('assertIsNotNone', (None,),
+ ["^unexpectedly None$", "^oops$",
+ "^unexpectedly None$",
+ "^unexpectedly None : oops$"])
+
+
 ######################################################################
 ## Main
 ######################################################################
@@ -2456,7 +2996,7 @@
 def test_main():
 support.run_unittest(Test_TestCase, Test_TestLoader,
 Test_TestSuite, Test_TestResult, Test_FunctionTestCase,
- Test_TestSkipping, Test_Assertions)
+ Test_TestSkipping, Test_Assertions, TestLongMessage)
 
 if __name__ == "__main__":
 test_main()
Modified: python/branches/py3k-short-float-repr/Lib/test/test_urllib.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_urllib.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_urllib.py	Sun Apr 5 01:04:14 2009
@@ -830,6 +830,21 @@
 "url2pathname() failed; %s != %s" %
 (expect, result))
 
+class Utility_Tests(unittest.TestCase):
+ """Testcase to test the various utility functions in the urllib."""
+
+ def test_splitpasswd(self):
+ """Some of password examples are not sensible, but it is added to
+ confirming to RFC2617 and addressing issue4675.
+ """
+ self.assertEqual(('user', 'ab'),urllib.parse.splitpasswd('user:ab'))
+ self.assertEqual(('user', 'a\nb'),urllib.parse.splitpasswd('user:a\nb'))
+ self.assertEqual(('user', 'a\tb'),urllib.parse.splitpasswd('user:a\tb'))
+ self.assertEqual(('user', 'a\rb'),urllib.parse.splitpasswd('user:a\rb'))
+ self.assertEqual(('user', 'a\fb'),urllib.parse.splitpasswd('user:a\fb'))
+ self.assertEqual(('user', 'a\vb'),urllib.parse.splitpasswd('user:a\vb'))
+ self.assertEqual(('user', 'a:b'),urllib.parse.splitpasswd('user:a:b'))
+
 # Just commented them out.
 # Can't really tell why keep failing in windows and sparc.
 # Everywhere else they work ok, but on those machines, someteimes
@@ -920,6 +935,7 @@
 UnquotingTests,
 urlencode_Tests,
 Pathname_Tests,
+ Utility_Tests,
 #FTPWrapperTests,
 )
 
Modified: python/branches/py3k-short-float-repr/Lib/test/test_urllib2.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_urllib2.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_urllib2.py	Sun Apr 5 01:04:14 2009
@@ -683,8 +683,13 @@
 self.msg = msg
 self.status = status
 self.reason = reason
+ self.code = 200
 def read(self):
 return ''
+ def info(self):
+ return {}
+ def geturl(self):
+ return self.url
 class MockHTTPClass:
 def __init__(self):
 self.level = 0
Modified: python/branches/py3k-short-float-repr/Lib/test/test_urllib2net.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_urllib2net.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_urllib2net.py	Sun Apr 5 01:04:14 2009
@@ -195,7 +195,7 @@
 def test_http_basic(self):
 self.assertTrue(socket.getdefaulttimeout() is None)
 u = _urlopen_with_retry("http://www.python.org")
- self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None)
+ self.assertTrue(u.fp.raw._sock.gettimeout() is None)
 
 def test_http_default_timeout(self):
 self.assertTrue(socket.getdefaulttimeout() is None)
@@ -204,7 +204,7 @@
 u = _urlopen_with_retry("http://www.python.org")
 finally:
 socket.setdefaulttimeout(None)
- self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60)
+ self.assertEqual(u.fp.raw._sock.gettimeout(), 60)
 
 def test_http_no_timeout(self):
 self.assertTrue(socket.getdefaulttimeout() is None)
@@ -213,11 +213,11 @@
 u = _urlopen_with_retry("http://www.python.org", timeout=None)
 finally:
 socket.setdefaulttimeout(None)
- self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None)
+ self.assertTrue(u.fp.raw._sock.gettimeout() is None)
 
 def test_http_timeout(self):
 u = _urlopen_with_retry("http://www.python.org", timeout=120)
- self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 120)
+ self.assertEqual(u.fp.raw._sock.gettimeout(), 120)
 
 FTP_HOST = "ftp://ftp.mirror.nl/pub/mirror/gnu/"
 
Modified: python/branches/py3k-short-float-repr/Lib/test/test_urlparse.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_urlparse.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_urlparse.py	Sun Apr 5 01:04:14 2009
@@ -97,6 +97,9 @@
 '', '', ''),
 ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf',
 '', '')),
+ ('nfs://server/path/to/file.txt',
+ ('nfs', 'server', '/path/to/file.txt', '', '', ''),
+ ('nfs', 'server', '/path/to/file.txt', '', '')),
 ('svn+ssh://svn.zope.org/repos/main/ZConfig/trunk/',
 ('svn+ssh', 'svn.zope.org', '/repos/main/ZConfig/trunk/',
 '', '', ''),
Modified: python/branches/py3k-short-float-repr/Lib/test/test_wait4.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_wait4.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_wait4.py	Sun Apr 5 01:04:14 2009
@@ -4,17 +4,12 @@
 import os
 import time
 from test.fork_wait import ForkWait
-from test.support import run_unittest, reap_children
+from test.support import run_unittest, reap_children, get_attribute
 
-try:
- os.fork
-except AttributeError:
- raise unittest.SkipTest("os.fork not defined -- skipping test_wait4")
+# If either of these do not exist, skip this test.
+get_attribute(os, 'fork')
+get_attribute(os, 'wait4')
 
-try:
- os.wait4
-except AttributeError:
- raise unittest.SkipTest("os.wait4 not defined -- skipping test_wait4")
 
 class Wait4Test(ForkWait):
 def wait_impl(self, cpid):
Modified: python/branches/py3k-short-float-repr/Lib/test/test_warnings.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_warnings.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_warnings.py	Sun Apr 5 01:04:14 2009
@@ -423,6 +423,41 @@
 finally:
 self.module.onceregistry = original_registry
 
+ def test_default_action(self):
+ # Replacing or removing defaultaction should be okay.
+ message = UserWarning("defaultaction test")
+ original = self.module.defaultaction
+ try:
+ with original_warnings.catch_warnings(record=True,
+ module=self.module) as w:
+ self.module.resetwarnings()
+ registry = {}
+ self.module.warn_explicit(message, UserWarning, "<test>", 42,
+ registry=registry)
+ self.assertEqual(w[-1].message, message)
+ self.assertEqual(len(w), 1)
+ self.assertEqual(len(registry), 1)
+ del w[:]
+ # Test removal.
+ del self.module.defaultaction
+ __warningregistry__ = {}
+ registry = {}
+ self.module.warn_explicit(message, UserWarning, "<test>", 43,
+ registry=registry)
+ self.assertEqual(w[-1].message, message)
+ self.assertEqual(len(w), 1)
+ self.assertEqual(len(registry), 1)
+ del w[:]
+ # Test setting.
+ self.module.defaultaction = "ignore"
+ __warningregistry__ = {}
+ registry = {}
+ self.module.warn_explicit(message, UserWarning, "<test>", 44,
+ registry=registry)
+ self.assertEqual(len(w), 0)
+ finally:
+ self.module.defaultaction = original
+
 def test_showwarning_missing(self):
 # Test that showwarning() missing is okay.
 text = 'del showwarning test'
@@ -435,14 +470,14 @@
 self.failUnless(text in result)
 
 def test_showwarning_not_callable(self):
- self.module.filterwarnings("always", category=UserWarning)
- old_showwarning = self.module.showwarning
- self.module.showwarning = 23
- try:
- self.assertRaises(TypeError, self.module.warn, "Warning!")
- finally:
- self.module.showwarning = old_showwarning
- self.module.resetwarnings()
+ with original_warnings.catch_warnings(module=self.module):
+ self.module.filterwarnings("always", category=UserWarning)
+ old_showwarning = self.module.showwarning
+ self.module.showwarning = 23
+ try:
+ self.assertRaises(TypeError, self.module.warn, "Warning!")
+ finally:
+ self.module.showwarning = old_showwarning
 
 def test_show_warning_output(self):
 # With showarning() missing, make sure that output is okay.
Modified: python/branches/py3k-short-float-repr/Lib/test/test_winreg.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_winreg.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_winreg.py	Sun Apr 5 01:04:14 2009
@@ -2,12 +2,15 @@
 # Test the windows specific win32reg module.
 # Only win32reg functions not hit here: FlushKey, LoadKey and SaveKey
 
-from winreg import *
 import os, sys
 import unittest
-
 from test import support
 
+# Do this first so test will be skipped if module doesn't exist
+support.import_module('winreg')
+# Now import everything
+from winreg import *
+
 test_key_name = "SOFTWARE\\Python Registry Test Key - Delete Me"
 
 test_data = [
Modified: python/branches/py3k-short-float-repr/Lib/test/test_winsound.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_winsound.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_winsound.py	Sun Apr 5 01:04:14 2009
@@ -3,10 +3,12 @@
 import unittest
 from test import support
 support.requires('audio')
-import winsound, time
+import time
 import os
 import subprocess
 
+winsound = support.import_module('winsound')
+
 
 class BeepTest(unittest.TestCase):
 # As with PlaySoundTest, incorporate the _have_soundcard() check
Modified: python/branches/py3k-short-float-repr/Lib/test/test_xml_etree_c.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_xml_etree_c.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_xml_etree_c.py	Sun Apr 5 01:04:14 2009
@@ -5,7 +5,7 @@
 
 from test import support
 
-from xml.etree import cElementTree as ET
+ET = support.import_module('xml.etree.cElementTree')
 
 SAMPLE_XML = """
 <body>
Modified: python/branches/py3k-short-float-repr/Lib/test/test_xmlrpc.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_xmlrpc.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_xmlrpc.py	Sun Apr 5 01:04:14 2009
@@ -9,6 +9,7 @@
 import http.client
 import socket
 import os
+import re
 from test import support
 
 alist = [{'astring': 'foo at bar.baz.spam',
@@ -352,6 +353,19 @@
 # protocol error; provide additional information in test output
 self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
 
+ def test_nonascii(self):
+ start_string = 'P\N{LATIN SMALL LETTER Y WITH CIRCUMFLEX}t'
+ end_string = 'h\N{LATIN SMALL LETTER O WITH HORN}n'
+ try:
+ p = xmlrpclib.ServerProxy(URL)
+ self.assertEqual(p.add(start_string, end_string),
+ start_string + end_string)
+ 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", "")))
+
 # [ch] The test 404 is causing lots of false alarms.
 def XXXtest_404(self):
 # send POST with http.client, it should return 404 header and
@@ -598,7 +612,11 @@
 sys.stdin = open("xmldata.txt", "r")
 sys.stdout = open(support.TESTFN, "w")
 
- self.cgi.handle_request()
+ os.environ['CONTENT_LENGTH'] = str(len(data))
+ try:
+ self.cgi.handle_request()
+ finally:
+ del os.environ['CONTENT_LENGTH']
 
 sys.stdin.close()
 sys.stdout.close()
@@ -612,9 +630,21 @@
 # need only xml
 self.assertRaises(xmlrpclib.Fault, xmlrpclib.loads, handle[44:])
 
+ # Also test the content-length returned by handle_request
+ # Using the same test method inorder to avoid all the datapassing
+ # boilerplate code.
+ # Test for bug: http://bugs.python.org/issue5040
+
+ content = handle[handle.find("<?xml"):]
+
+ self.assertEquals(
+ int(re.search('Content-Length: (\d+)', handle).group(1)),
+ len(content))
+
 os.remove("xmldata.txt")
 os.remove(support.TESTFN)
 
+
 def test_main():
 xmlrpc_tests = [XMLRPCTestCase, HelperTestCase, DateTimeTestCase,
 BinaryTestCase, FaultTestCase]
Modified: python/branches/py3k-short-float-repr/Lib/test/test_zlib.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/test/test_zlib.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/test/test_zlib.py	Sun Apr 5 01:04:14 2009
@@ -1,9 +1,10 @@
 import unittest
 from test import support
-import zlib
 import binascii
 import random
 
+zlib = support.import_module('zlib')
+
 
 class ChecksumTestCase(unittest.TestCase):
 # checksum test cases
Modified: python/branches/py3k-short-float-repr/Lib/timeit.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/timeit.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/timeit.py	Sun Apr 5 01:04:14 2009
@@ -92,11 +92,11 @@
 
 def _template_func(setup, func):
 """Create a timer function. Used if the "statement" is a callable."""
- def inner(_it, _timer):
+ def inner(_it, _timer, _func=func):
 setup()
 _t0 = _timer()
 for _i in _it:
- func()
+ _func()
 _t1 = _timer()
 return _t1 - _t0
 return inner
Modified: python/branches/py3k-short-float-repr/Lib/trace.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/trace.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/trace.py	Sun Apr 5 01:04:14 2009
@@ -48,6 +48,7 @@
 r.write_results(show_missing=True, coverdir="/tmp")
 """
 
+import io
 import linecache
 import os
 import re
@@ -224,6 +225,13 @@
 print(("Skipping counts file %r: %s"
 % (self.infile, err)), file=sys.stderr)
 
+ def is_ignored_filename(self, filename):
+ """Return True if the filename does not refer to a file
+ we want to have reported.
+ """
+ return (filename == "<string>" or
+ filename.startswith("<doctest "))
+
 def update(self, other):
 """Merge in the data from another CoverageResults"""
 counts = self.counts
@@ -257,7 +265,8 @@
 print()
 print("calling relationships:")
 lastfile = lastcfile = ""
- for ((pfile, pmod, pfunc), (cfile, cmod, cfunc)) in sorted(self.callers.keys()):
+ for ((pfile, pmod, pfunc), (cfile, cmod, cfunc)) \
+ in sorted(self.callers.keys()):
 if pfile != lastfile:
 print()
 print("***", pfile, "***")
@@ -279,10 +288,7 @@
 sums = {}
 
 for filename, count in per_file.items():
- # skip some "files" we don't care about...
- if filename == "<string>":
- continue
- if filename.startswith("<doctest "):
+ if self.is_ignored_filename(filename):
 continue
 
 if filename.endswith((".pyc", ".pyo")):
@@ -391,7 +397,7 @@
 linenos.update(find_lines(c, strs))
 return linenos
 
-def find_strings(filename):
+def find_strings(filename, encoding=None):
 """Return a dict of possible docstring positions.
 
 The dict maps line numbers to strings. There is an entry for
@@ -402,7 +408,7 @@
 # If the first token is a string, then it's the module docstring.
 # Add this special case so that the test in the loop passes.
 prev_ttype = token.INDENT
- f = open(filename)
+ f = open(filename, encoding=encoding)
 for ttype, tstr, start, end, line in tokenize.generate_tokens(f.readline):
 if ttype == token.STRING:
 if prev_ttype == token.INDENT:
@@ -417,13 +423,15 @@
 def find_executable_linenos(filename):
 """Return dict where keys are line numbers in the line number table."""
 try:
- prog = open(filename, "rU").read()
+ with io.FileIO(filename, 'r') as file:
+ encoding, lines = tokenize.detect_encoding(file.readline)
+ prog = open(filename, "r", encoding=encoding).read()
 except IOError as err:
 print(("Not printing coverage data for %r: %s"
 % (filename, err)), file=sys.stderr)
 return {}
 code = compile(prog, filename, "exec")
- strs = find_strings(filename)
+ strs = find_strings(filename, encoding)
 return find_lines(code, strs)
 
 class Trace:
Modified: python/branches/py3k-short-float-repr/Lib/unittest.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/unittest.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/unittest.py	Sun Apr 5 01:04:14 2009
@@ -14,11 +14,11 @@
 
 class IntegerArithmenticTestCase(unittest.TestCase):
 def testAdd(self): ## test method names begin 'test*'
- self.assertEquals((1 + 2), 3)
- self.assertEquals(0 + 1, 1)
+ self.assertEqual((1 + 2), 3)
+ self.assertEqual(0 + 1, 1)
 def testMultiply(self):
- self.assertEquals((0 * 10), 0)
- self.assertEquals((5 * 8), 40)
+ self.assertEqual((0 * 10), 0)
+ self.assertEqual((5 * 8), 40)
 
 if __name__ == '__main__':
 unittest.main()
@@ -45,12 +45,16 @@
 SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 '''
 
-import time
+import difflib
+import functools
+import os
+import pprint
+import re
 import sys
+import time
 import traceback
-import os
 import types
-import functools
+import warnings
 
 ##############################################################################
 # Exported classes and functions
@@ -143,7 +147,6 @@
 raise _UnexpectedSuccess
 return wrapper
 
-
 __unittest = 1
 
 class TestResult(object):
@@ -239,10 +242,12 @@
 len(self.failures))
 
 
-class AssertRaisesContext(object):
+class _AssertRaisesContext(object):
+ """A context manager used to implement TestCase.assertRaises* methods."""
 
 
- def __init__(self, expected, test_case, callable_obj=None):
+ def __init__(self, expected, test_case, callable_obj=None,
+ expected_regexp=None):
 self.expected = expected
 self.failureException = test_case.failureException
 if callable_obj is not None:
@@ -252,6 +257,7 @@
 self.obj_name = str(callable_obj)
 else:
 self.obj_name = None
+ self.expected_regex = expected_regexp
 
 def __enter__(self):
 pass
@@ -268,10 +274,30 @@
 else:
 raise self.failureException("{0} not raised"
 .format(exc_name))
- if issubclass(exc_type, self.expected):
+ if not issubclass(exc_type, self.expected):
+ # let unexpected exceptions pass through
+ return False
+ if self.expected_regex is None:
 return True
- # Let unexpected exceptions skip through
- return False
+
+ expected_regexp = self.expected_regex
+ if isinstance(expected_regexp, (bytes, str)):
+ expected_regexp = re.compile(expected_regexp)
+ if not expected_regexp.search(str(exc_value)):
+ raise self.failureException('"%s" does not match "%s"' %
+ (expected_regexp.pattern, str(exc_value)))
+ return True
+
+
+class _AssertWrapper(object):
+ """Wrap entries in the _type_equality_funcs registry to make them deep
+ copyable."""
+
+ def __init__(self, function):
+ self.function = function
+
+ def __deepcopy__(self, memo):
+ memo[id(self)] = self
 
 
 class TestCase(object):
@@ -302,6 +328,13 @@
 
 failureException = AssertionError
 
+ # This attribute determines whether long messages (including repr of
+ # objects used in assert methods) will be printed on failure in *addition*
+ # to any explicit message passed.
+
+ longMessage = False
+
+
 def __init__(self, methodName='runTest'):
 """Create an instance of the class that will use the named test
 method when executed. Raises a ValueError if the instance does
@@ -315,6 +348,31 @@
 (self.__class__, methodName))
 self._testMethodDoc = testMethod.__doc__
 
+ # Map types to custom assertEqual functions that will compare
+ # instances of said type in more detail to generate a more useful
+ # error message.
+ self._type_equality_funcs = {}
+ self.addTypeEqualityFunc(dict, self.assertDictEqual)
+ self.addTypeEqualityFunc(list, self.assertListEqual)
+ self.addTypeEqualityFunc(tuple, self.assertTupleEqual)
+ self.addTypeEqualityFunc(set, self.assertSetEqual)
+ self.addTypeEqualityFunc(frozenset, self.assertSetEqual)
+
+ def addTypeEqualityFunc(self, typeobj, function):
+ """Add a type specific assertEqual style function to compare a type.
+
+ This method is for use by TestCase subclasses that need to register
+ their own type equality functions to provide nicer error messages.
+
+ Args:
+ typeobj: The data type to call this function on when both values
+ are of the same type in assertEqual().
+ function: The callable taking two arguments and an optional
+ msg= argument that raises self.failureException with a
+ useful error message when the two arguments are not equal.
+ """
+ self._type_equality_funcs[typeobj] = _AssertWrapper(function)
+
 def setUp(self):
 "Hook method for setting up the test fixture before exercising it."
 pass
@@ -330,14 +388,22 @@
 return TestResult()
 
 def shortDescription(self):
- """Returns a one-line description of the test, or None if no
- description has been provided.
+ """Returns both the test method name and first line of its docstring.
 
- The default implementation of this method returns the first line of
- the specified test method's docstring.
+ If no docstring is given, only returns the method name.
+
+ This method overrides unittest.TestCase.shortDescription(), which
+ only returns the first line of the docstring, obscuring the name
+ of the test upon failure.
 """
- doc = self._testMethodDoc
- return doc and doc.split("\n")[0].strip() or None
+ desc = str(self)
+ doc_first_line = None
+
+ if self._testMethodDoc:
+ doc_first_line = self._testMethodDoc.split("\n")[0].strip()
+ if doc_first_line:
+ desc = '\n'.join((desc, doc_first_line))
+ return desc
 
 def id(self):
 return "%s.%s" % (_strclass(self.__class__), self._testMethodName)
@@ -419,17 +485,36 @@
 """Fail immediately, with the given message."""
 raise self.failureException(msg)
 
- def failIf(self, expr, msg=None):
+ def assertFalse(self, expr, msg=None):
 "Fail the test if the expression is true."
 if expr:
+ msg = self._formatMessage(msg, "%r is not False" % expr)
 raise self.failureException(msg)
 
- def failUnless(self, expr, msg=None):
+ def assertTrue(self, expr, msg=None):
 """Fail the test unless the expression is true."""
 if not expr:
+ msg = self._formatMessage(msg, "%r is not True" % expr)
 raise self.failureException(msg)
 
- def failUnlessRaises(self, excClass, callableObj=None, *args, **kwargs):
+ def _formatMessage(self, msg, standardMsg):
+ """Honour the longMessage attribute when generating failure messages.
+ If longMessage is False this means:
+ * Use only an explicit message if it is provided
+ * Otherwise use the standard message for the assert
+
+ If longMessage is True:
+ * Use the standard message
+ * If an explicit message is provided, plus ' : ' and the explicit message
+ """
+ if not self.longMessage:
+ return msg or standardMsg
+ if msg is None:
+ return standardMsg
+ return standardMsg + ' : ' + msg
+
+
+ def assertRaises(self, excClass, callableObj=None, *args, **kwargs):
 """Fail unless an exception of class excClass is thrown
 by callableObj when invoked with arguments args and keyword
 arguments kwargs. If a different type of exception is
@@ -440,30 +525,62 @@
 If called with callableObj omitted or None, will return a
 context object used like this::
 
- with self.failUnlessRaises(some_error_class):
+ with self.assertRaises(some_error_class):
 do_something()
 """
- context = AssertRaisesContext(excClass, self, callableObj)
+ context = _AssertRaisesContext(excClass, self, callableObj)
 if callableObj is None:
 return context
 with context:
 callableObj(*args, **kwargs)
 
- def failUnlessEqual(self, first, second, msg=None):
+ def _getAssertEqualityFunc(self, first, second):
+ """Get a detailed comparison function for the types of the two args.
+
+ Returns: A callable accepting (first, second, msg=None) that will
+ raise a failure exception if first != second with a useful human
+ readable error message for those types.
+ """
+ #
+ # NOTE(gregory.p.smith): I considered isinstance(first, type(second))
+ # and vice versa. I opted for the conservative approach in case
+ # subclasses are not intended to be compared in detail to their super
+ # class instances using a type equality func. This means testing
+ # subtypes won't automagically use the detailed comparison. Callers
+ # should use their type specific assertSpamEqual method to compare
+ # subclasses if the detailed comparison is desired and appropriate.
+ # See the discussion in http://bugs.python.org/issue2578.
+ #
+ if type(first) is type(second):
+ asserter = self._type_equality_funcs.get(type(first))
+ if asserter is not None:
+ return asserter.function
+
+ return self._baseAssertEqual
+
+ def _baseAssertEqual(self, first, second, msg=None):
+ """The default assertEqual implementation, not type specific."""
+ if not first == second:
+ standardMsg = '%r != %r' % (first, second)
+ msg = self._formatMessage(msg, standardMsg)
+ raise self.failureException(msg)
+
+ def assertEqual(self, first, second, msg=None):
 """Fail if the two objects are unequal as determined by the '=='
 operator.
 """
- if not first == second:
- raise self.failureException(msg or '%r != %r' % (first, second))
+ assertion_func = self._getAssertEqualityFunc(first, second)
+ assertion_func(first, second, msg=msg)
 
- def failIfEqual(self, first, second, msg=None):
+ def assertNotEqual(self, first, second, msg=None):
 """Fail if the two objects are equal as determined by the '=='
 operator.
 """
- if first == second:
- raise self.failureException(msg or '%r == %r' % (first, second))
+ if not first != second:
+ msg = self._formatMessage(msg, '%r == %r' % (first, second))
+ raise self.failureException(msg)
 
- def failUnlessAlmostEqual(self, first, second, *, places=7, msg=None):
+ def assertAlmostEqual(self, first, second, *, places=7, msg=None):
 """Fail if the two objects are unequal as determined by their
 difference rounded to the given number of decimal places
 (default 7) and comparing to zero.
@@ -472,10 +589,11 @@
 as significant digits (measured from the most signficant digit).
 """
 if round(abs(second-first), places) != 0:
- raise self.failureException(
- msg or '%r != %r within %r places' % (first, second, places))
+ standardMsg = '%r != %r within %r places' % (first, second, places)
+ msg = self._formatMessage(msg, standardMsg)
+ raise self.failureException(msg)
 
- def failIfAlmostEqual(self, first, second, *, places=7, msg=None):
+ def assertNotAlmostEqual(self, first, second, *, places=7, msg=None):
 """Fail if the two objects are equal as determined by their
 difference rounded to the given number of decimal places
 (default 7) and comparing to zero.
@@ -484,26 +602,409 @@
 as significant digits (measured from the most signficant digit).
 """
 if round(abs(second-first), places) == 0:
- raise self.failureException(
- msg or '%r == %r within %r places' % (first, second, places))
+ standardMsg = '%r == %r within %r places' % (first, second, places)
+ msg = self._formatMessage(msg, standardMsg)
+ raise self.failureException(msg)
 
 # Synonyms for assertion methods
 
- assertEqual = assertEquals = failUnlessEqual
+ # The plurals are undocumented. Keep them that way to discourage use.
+ # Do not add more. Do not remove.
+ # Going through a deprecation cycle on these would annoy many people.
+ assertEquals = assertEqual
+ assertNotEquals = assertNotEqual
+ assertAlmostEquals = assertAlmostEqual
+ assertNotAlmostEquals = assertNotAlmostEqual
+ assert_ = assertTrue
+
+ # These fail* assertion method names are pending deprecation and will
+ # be a DeprecationWarning in 3.2; http://bugs.python.org/issue2578
+ def _deprecate(original_func):
+ def deprecated_func(*args, **kwargs):
+ warnings.warn(
+ 'Please use {0} instead.'.format(original_func.__name__),
+ PendingDeprecationWarning, 2)
+ return original_func(*args, **kwargs)
+ return deprecated_func
+
+ failUnlessEqual = _deprecate(assertEqual)
+ failIfEqual = _deprecate(assertNotEqual)
+ failUnlessAlmostEqual = _deprecate(assertAlmostEqual)
+ failIfAlmostEqual = _deprecate(assertNotAlmostEqual)
+ failUnless = _deprecate(assertTrue)
+ failUnlessRaises = _deprecate(assertRaises)
+ failIf = _deprecate(assertFalse)
+
+ def assertSequenceEqual(self, seq1, seq2, msg=None, seq_type=None):
+ """An equality assertion for ordered sequences (like lists and tuples).
+
+ For the purposes of this function, a valid orderd sequence type is one
+ which can be indexed, has a length, and has an equality operator.
+
+ Args:
+ seq1: The first sequence to compare.
+ seq2: The second sequence to compare.
+ seq_type: The expected datatype of the sequences, or None if no
+ datatype should be enforced.
+ msg: Optional message to use on failure instead of a list of
+ differences.
+ """
+ if seq_type != None:
+ seq_type_name = seq_type.__name__
+ if not isinstance(seq1, seq_type):
+ raise self.failureException('First sequence is not a %s: %r'
+ % (seq_type_name, seq1))
+ if not isinstance(seq2, seq_type):
+ raise self.failureException('Second sequence is not a %s: %r'
+ % (seq_type_name, seq2))
+ else:
+ seq_type_name = "sequence"
 
- assertNotEqual = assertNotEquals = failIfEqual
+ differing = None
+ try:
+ len1 = len(seq1)
+ except (TypeError, NotImplementedError):
+ differing = 'First %s has no length. Non-sequence?' % (
+ seq_type_name)
 
- assertAlmostEqual = assertAlmostEquals = failUnlessAlmostEqual
+ if differing is None:
+ try:
+ len2 = len(seq2)
+ except (TypeError, NotImplementedError):
+ differing = 'Second %s has no length. Non-sequence?' % (
+ seq_type_name)
 
- assertNotAlmostEqual = assertNotAlmostEquals = failIfAlmostEqual
+ if differing is None:
+ if seq1 == seq2:
+ return
 
- assertRaises = failUnlessRaises
+ for i in range(min(len1, len2)):
+ try:
+ item1 = seq1[i]
+ except (TypeError, IndexError, NotImplementedError):
+ differing = ('Unable to index element %d of first %s\n' %
+ (i, seq_type_name))
+ break
+
+ try:
+ item2 = seq2[i]
+ except (TypeError, IndexError, NotImplementedError):
+ differing = ('Unable to index element %d of second %s\n' %
+ (i, seq_type_name))
+ break
+
+ if item1 != item2:
+ differing = ('First differing element %d:\n%s\n%s\n' %
+ (i, item1, item2))
+ break
+ else:
+ if (len1 == len2 and seq_type is None and
+ type(seq1) != type(seq2)):
+ # The sequences are the same, but have differing types.
+ return
+ # A catch-all message for handling arbitrary user-defined
+ # sequences.
+ differing = '%ss differ:\n' % seq_type_name.capitalize()
+ if len1 > len2:
+ differing = ('First %s contains %d additional '
+ 'elements.\n' % (seq_type_name, len1 - len2))
+ try:
+ differing += ('First extra element %d:\n%s\n' %
+ (len2, seq1[len2]))
+ except (TypeError, IndexError, NotImplementedError):
+ differing += ('Unable to index element %d '
+ 'of first %s\n' % (len2, seq_type_name))
+ elif len1 < len2:
+ differing = ('Second %s contains %d additional '
+ 'elements.\n' % (seq_type_name, len2 - len1))
+ try:
+ differing += ('First extra element %d:\n%s\n' %
+ (len1, seq2[len1]))
+ except (TypeError, IndexError, NotImplementedError):
+ differing += ('Unable to index element %d '
+ 'of second %s\n' % (len1, seq_type_name))
+ standardMsg = differing + '\n'.join(difflib.ndiff(pprint.pformat(seq1).splitlines(),
+ pprint.pformat(seq2).splitlines()))
+ msg = self._formatMessage(msg, standardMsg)
+ self.fail(msg)
+
+ def assertListEqual(self, list1, list2, msg=None):
+ """A list-specific equality assertion.
+
+ Args:
+ list1: The first list to compare.
+ list2: The second list to compare.
+ msg: Optional message to use on failure instead of a list of
+ differences.
+
+ """
+ self.assertSequenceEqual(list1, list2, msg, seq_type=list)
+
+ def assertTupleEqual(self, tuple1, tuple2, msg=None):
+ """A tuple-specific equality assertion.
+
+ Args:
+ tuple1: The first tuple to compare.
+ tuple2: The second tuple to compare.
+ msg: Optional message to use on failure instead of a list of
+ differences.
+ """
+ self.assertSequenceEqual(tuple1, tuple2, msg, seq_type=tuple)
+
+ def assertSetEqual(self, set1, set2, msg=None):
+ """A set-specific equality assertion.
+
+ Args:
+ set1: The first set to compare.
+ set2: The second set to compare.
+ msg: Optional message to use on failure instead of a list of
+ differences.
+
+ For more general containership equality, assertSameElements will work
+ with things other than sets. This uses ducktyping to support
+ different types of sets, and is optimized for sets specifically
+ (parameters must support a difference method).
+ """
+ try:
+ difference1 = set1.difference(set2)
+ except TypeError as e:
+ self.fail('invalid type when attempting set difference: %s' % e)
+ except AttributeError as e:
+ self.fail('first argument does not support set difference: %s' % e)
+
+ try:
+ difference2 = set2.difference(set1)
+ except TypeError as e:
+ self.fail('invalid type when attempting set difference: %s' % e)
+ except AttributeError as e:
+ self.fail('second argument does not support set difference: %s' % e)
+
+ if not (difference1 or difference2):
+ return
+
+ lines = []
+ if difference1:
+ lines.append('Items in the first set but not the second:')
+ for item in difference1:
+ lines.append(repr(item))
+ if difference2:
+ lines.append('Items in the second set but not the first:')
+ for item in difference2:
+ lines.append(repr(item))
+
+ standardMsg = '\n'.join(lines)
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertIn(self, member, container, msg=None):
+ """Just like self.assertTrue(a in b), but with a nicer default message."""
+ if member not in container:
+ standardMsg = '%r not found in %r' % (member, container)
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertNotIn(self, member, container, msg=None):
+ """Just like self.assertTrue(a not in b), but with a nicer default message."""
+ if member in container:
+ standardMsg = '%r unexpectedly found in %r' % (member, container)
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertDictEqual(self, d1, d2, msg=None):
+ self.assert_(isinstance(d1, dict), 'First argument is not a dictionary')
+ self.assert_(isinstance(d2, dict), 'Second argument is not a dictionary')
+
+ if d1 != d2:
+ standardMsg = ('\n' + '\n'.join(difflib.ndiff(
+ pprint.pformat(d1).splitlines(),
+ pprint.pformat(d2).splitlines())))
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertDictContainsSubset(self, expected, actual, msg=None):
+ """Checks whether actual is a superset of expected."""
+ missing = []
+ mismatched = []
+ for key, value in expected.items():
+ if key not in actual:
+ missing.append(key)
+ elif value != actual[key]:
+ mismatched.append('%s, expected: %s, actual: %s' % (key, value, actual[key]))
+
+ if not (missing or mismatched):
+ return
+
+ standardMsg = ''
+ if missing:
+ standardMsg = 'Missing: %r' % ','.join(missing)
+ if mismatched:
+ if standardMsg:
+ standardMsg += '; '
+ standardMsg += 'Mismatched values: %s' % ','.join(mismatched)
+
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertSameElements(self, expected_seq, actual_seq, msg=None):
+ """An unordered sequence specific comparison.
+
+ Raises with an error message listing which elements of expected_seq
+ are missing from actual_seq and vice versa if any.
+ """
+ try:
+ expected = set(expected_seq)
+ actual = set(actual_seq)
+ missing = list(expected.difference(actual))
+ unexpected = list(actual.difference(expected))
+ missing.sort()
+ unexpected.sort()
+ except TypeError:
+ # Fall back to slower list-compare if any of the objects are
+ # not hashable.
+ expected = list(expected_seq)
+ actual = list(actual_seq)
+ try:
+ expected.sort()
+ actual.sort()
+ except TypeError:
+ missing, unexpected = _UnorderableListDifference(expected, actual)
+ else:
+ missing, unexpected = _SortedListDifference(expected, actual)
+ errors = []
+ if missing:
+ errors.append('Expected, but missing:\n %r' % missing)
+ if unexpected:
+ errors.append('Unexpected, but present:\n %r' % unexpected)
+ if errors:
+ standardMsg = '\n'.join(errors)
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertMultiLineEqual(self, first, second, msg=None):
+ """Assert that two multi-line strings are equal."""
+ self.assert_(isinstance(first, str), (
+ 'First argument is not a string'))
+ self.assert_(isinstance(second, str), (
+ 'Second argument is not a string'))
+
+ if first != second:
+ standardMsg = '\n' + ''.join(difflib.ndiff(first.splitlines(True), second.splitlines(True)))
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertLess(self, a, b, msg=None):
+ """Just like self.assertTrue(a < b), but with a nicer default message."""
+ if not a < b:
+ standardMsg = '%r not less than %r' % (a, b)
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertLessEqual(self, a, b, msg=None):
+ """Just like self.assertTrue(a <= b), but with a nicer default message."""
+ if not a <= b:
+ standardMsg = '%r not less than or equal to %r' % (a, b)
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertGreater(self, a, b, msg=None):
+ """Just like self.assertTrue(a > b), but with a nicer default message."""
+ if not a > b:
+ standardMsg = '%r not greater than %r' % (a, b)
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertGreaterEqual(self, a, b, msg=None):
+ """Just like self.assertTrue(a >= b), but with a nicer default message."""
+ if not a >= b:
+ standardMsg = '%r not greater than or equal to %r' % (a, b)
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertIsNone(self, obj, msg=None):
+ """Same as self.assertTrue(obj is None), with a nicer default message."""
+ if obj is not None:
+ standardMsg = '%r is not None' % obj
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertIsNotNone(self, obj, msg=None):
+ """Included for symmetry with assertIsNone."""
+ if obj is None:
+ standardMsg = 'unexpectedly None'
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertRaisesRegexp(self, expected_exception, expected_regexp,
+ callable_obj=None, *args, **kwargs):
+ """Asserts that the message in a raised exception matches a regexp.
+
+ Args:
+ expected_exception: Exception class expected to be raised.
+ expected_regexp: Regexp (re pattern object or string) expected
+ to be found in error message.
+ callable_obj: Function to be called.
+ args: Extra args.
+ kwargs: Extra kwargs.
+ """
+ context = _AssertRaisesContext(expected_exception, self, callable_obj,
+ expected_regexp)
+ if callable_obj is None:
+ return context
+ with context:
+ callable_obj(*args, **kwargs)
+
+ def assertRegexpMatches(self, text, expected_regex, msg=None):
+ if isinstance(expected_regex, (str, bytes)):
+ expected_regex = re.compile(expected_regex)
+ if not expected_regex.search(text):
+ msg = msg or "Regexp didn't match"
+ msg = '%s: %r not found in %r' % (msg, expected_regex.pattern, text)
+ raise self.failureException(msg)
 
- assert_ = assertTrue = failUnless
 
- assertFalse = failIf
+def _SortedListDifference(expected, actual):
+ """Finds elements in only one or the other of two, sorted input lists.
 
+ Returns a two-element tuple of lists. The first list contains those
+ elements in the "expected" list but not in the "actual" list, and the
+ second contains those elements in the "actual" list but not in the
+ "expected" list. Duplicate elements in either input list are ignored.
+ """
+ i = j = 0
+ missing = []
+ unexpected = []
+ while True:
+ try:
+ e = expected[i]
+ a = actual[j]
+ if e < a:
+ missing.append(e)
+ i += 1
+ while expected[i] == e:
+ i += 1
+ elif e > a:
+ unexpected.append(a)
+ j += 1
+ while actual[j] == a:
+ j += 1
+ else:
+ i += 1
+ try:
+ while expected[i] == e:
+ i += 1
+ finally:
+ j += 1
+ while actual[j] == a:
+ j += 1
+ except IndexError:
+ missing.extend(expected[i:])
+ unexpected.extend(actual[j:])
+ break
+ return missing, unexpected
+
+def _UnorderableListDifference(expected, actual):
+ """Same behavior as _SortedListDifference but
+ for lists of unorderable items (like dicts).
+
+ As it does a linear search per item (remove) it
+ has O(n*n) performance."""
+ missing = []
+ while expected:
+ item = expected.pop()
+ try:
+ actual.remove(item)
+ except ValueError:
+ missing.append(item)
 
+ # anything left in actual is unexpected
+ return missing, actual
 
 class TestSuite(object):
 """A test suite is a composite test consisting of a number of TestCases.
@@ -611,52 +1112,52 @@
 
 def __init__(self, testFunc, setUp=None, tearDown=None, description=None):
 super(FunctionTestCase, self).__init__()
- self.__setUpFunc = setUp
- self.__tearDownFunc = tearDown
- self.__testFunc = testFunc
- self.__description = description
+ self._setUpFunc = setUp
+ self._tearDownFunc = tearDown
+ self._testFunc = testFunc
+ self._description = description
 
 def setUp(self):
- if self.__setUpFunc is not None:
- self.__setUpFunc()
+ if self._setUpFunc is not None:
+ self._setUpFunc()
 
 def tearDown(self):
- if self.__tearDownFunc is not None:
- self.__tearDownFunc()
+ if self._tearDownFunc is not None:
+ self._tearDownFunc()
 
 def runTest(self):
- self.__testFunc()
+ self._testFunc()
 
 def id(self):
- return self.__testFunc.__name__
+ return self._testFunc.__name__
 
 def __eq__(self, other):
 if not isinstance(other, self.__class__):
 return NotImplemented
 
- return self.__setUpFunc == other.__setUpFunc and \
- self.__tearDownFunc == other.__tearDownFunc and \
- self.__testFunc == other.__testFunc and \
- self.__description == other.__description
+ return self._setUpFunc == other._setUpFunc and \
+ self._tearDownFunc == other._tearDownFunc and \
+ self._testFunc == other._testFunc and \
+ self._description == other._description
 
 def __ne__(self, other):
 return not self == other
 
 def __hash__(self):
- return hash((type(self), self.__setUpFunc, self.__tearDownFunc,
- self.__testFunc, self.__description))
+ return hash((type(self), self._setUpFunc, self._tearDownFunc,
+ self._testFunc, self._description))
 
 def __str__(self):
 return "%s (%s)" % (_strclass(self.__class__),
 self.__testFunc.__name__)
 
 def __repr__(self):
- return "<%s testFunc=%s>" % (_strclass(self.__class__),
- self.__testFunc)
+ return "<%s testFunc=%s>" % (_strclass(self.__class__), self._testFunc)
 
 def shortDescription(self):
- if self.__description is not None: return self.__description
- doc = self.__testFunc.__doc__
+ if self._description is not None:
+ return self._description
+ doc = self._testFunc.__doc__
 return doc and doc.split("\n")[0].strip() or None
 
 
Modified: python/branches/py3k-short-float-repr/Lib/urllib/parse.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/urllib/parse.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/urllib/parse.py	Sun Apr 5 01:04:14 2009
@@ -19,7 +19,7 @@
 uses_netloc = ['ftp', 'http', 'gopher', 'nntp', 'telnet',
 'imap', 'wais', 'file', 'mms', 'https', 'shttp',
 'snews', 'prospero', 'rtsp', 'rtspu', 'rsync', '',
- 'svn', 'svn+ssh', 'sftp']
+ 'svn', 'svn+ssh', 'sftp','nfs']
 non_hierarchical = ['gopher', 'hdl', 'mailto', 'news',
 'telnet', 'wais', 'imap', 'snews', 'sip', 'sips']
 uses_params = ['ftp', 'hdl', 'prospero', 'http', 'imap',
@@ -645,7 +645,7 @@
 global _passwdprog
 if _passwdprog is None:
 import re
- _passwdprog = re.compile('^([^:]*):(.*)$')
+ _passwdprog = re.compile('^([^:]*):(.*)$',re.S)
 
 match = _passwdprog.match(user)
 if match: return match.group(1, 2)
Modified: python/branches/py3k-short-float-repr/Lib/urllib/request.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/urllib/request.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/urllib/request.py	Sun Apr 5 01:04:14 2009
@@ -1,6 +1,3 @@
-# Issues in merging urllib and urllib2:
-# 1. They both define a function named urlopen()
-
 """An extensible library for opening URLs using a variety of protocols
 
 The simplest way to use this module is to call the urlopen function,
@@ -83,6 +80,7 @@
 # abstract factory for opener
 
 import base64
+import bisect
 import email
 import hashlib
 import http.client
@@ -94,7 +92,6 @@
 import socket
 import sys
 import time
-import bisect
 
 from urllib.error import URLError, HTTPError, ContentTooShortError
 from urllib.parse import (
@@ -149,7 +146,7 @@
 comparison.
 
 """
- url = request.get_full_url()
+ url = request.full_url
 host = urlparse(url)[1]
 if host == "":
 host = request.get_header("Host", "")
@@ -163,11 +160,7 @@
 def __init__(self, url, data=None, headers={},
 origin_req_host=None, unverifiable=False):
 # unwrap('<URL:type://host/path>') --> 'type://host/path'
- self.__original = unwrap(url)
- self.type = None
- # self.__r_type is what's left after doing the splittype
- self.host = None
- self.port = None
+ self.full_url = unwrap(url)
 self.data = data
 self.headers = {}
 for key, value in headers.items():
@@ -177,26 +170,23 @@
 origin_req_host = request_host(self)
 self.origin_req_host = origin_req_host
 self.unverifiable = unverifiable
+ self._parse()
 
- def __getattr__(self, attr):
- # XXX this is a fallback mechanism to guard against these
- # methods getting called in a non-standard order. this may be
- # too complicated and/or unnecessary.
- # XXX should the __r_XXX attributes be public?
- if attr[:12] == '_Request__r_':
- name = attr[12:]
- if hasattr(Request, 'get_' + name):
- getattr(self, 'get_' + name)()
- return getattr(self, attr)
- raise AttributeError(attr)
+ def _parse(self):
+ self.type, rest = splittype(self.full_url)
+ if self.type is None:
+ raise ValueError("unknown url type: %s" % self.full_url)
+ self.host, self.selector = splithost(rest)
+ if self.host:
+ self.host = unquote(self.host)
 
 def get_method(self):
- if self.has_data():
+ if self.data is not None:
 return "POST"
 else:
 return "GET"
 
- # XXX these helper methods are lame
+ # Begin deprecated methods
 
 def add_data(self, data):
 self.data = data
@@ -208,37 +198,31 @@
 return self.data
 
 def get_full_url(self):
- return self.__original
+ return self.full_url
 
 def get_type(self):
- if self.type is None:
- self.type, self.__r_type = splittype(self.__original)
- if self.type is None:
- raise ValueError("unknown url type: %s" % self.__original)
 return self.type
 
 def get_host(self):
- if self.host is None:
- self.host, self.__r_host = splithost(self.__r_type)
- if self.host:
- self.host = unquote(self.host)
 return self.host
 
 def get_selector(self):
- return self.__r_host
+ return self.selector
 
- def set_proxy(self, host, type):
- self.host, self.type = host, type
- self.__r_host = self.__original
-
- def has_proxy(self):
- return self.__r_host == self.__original
+ def is_unverifiable(self):
+ return self.unverifiable
 
 def get_origin_req_host(self):
 return self.origin_req_host
 
- def is_unverifiable(self):
- return self.unverifiable
+ # End deprecated methods
+
+ def set_proxy(self, host, type):
+ self.host, self.type = host, type
+ self.selector = self.full_url
+
+ def has_proxy(self):
+ return self.selector == self.full_url
 
 def add_header(self, key, val):
 # useful for something like authentication
@@ -344,10 +328,10 @@
 else:
 req = fullurl
 if data is not None:
- req.add_data(data)
+ req.data = data
 
 req.timeout = timeout
- protocol = req.get_type()
+ protocol = req.type
 
 # pre-process request
 meth_name = protocol+"_request"
@@ -371,7 +355,7 @@
 if result:
 return result
 
- protocol = req.get_type()
+ protocol = req.type
 result = self._call_chain(self.handle_open, protocol, protocol +
 '_open', req)
 if result:
@@ -481,7 +465,7 @@
 
 class HTTPDefaultErrorHandler(BaseHandler):
 def http_error_default(self, req, fp, code, msg, hdrs):
- raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
+ raise HTTPError(req.full_url, code, msg, hdrs, fp)
 
 class HTTPRedirectHandler(BaseHandler):
 # maximum number of redirections to any single URL
@@ -504,7 +488,7 @@
 m = req.get_method()
 if (not (code in (301, 302, 303, 307) and m in ("GET", "HEAD")
 or code in (301, 302, 303) and m == "POST")):
- raise HTTPError(req.get_full_url(), code, msg, headers, fp)
+ raise HTTPError(req.full_url, code, msg, headers, fp)
 
 # Strictly (according to RFC 2616), 301 or 302 in response to
 # a POST MUST NOT cause a redirection without confirmation
@@ -518,7 +502,7 @@
 if k.lower() not in CONTENT_HEADERS)
 return Request(newurl,
 headers=newheaders,
- origin_req_host=req.get_origin_req_host(),
+ origin_req_host=req.origin_req_host,
 unverifiable=True)
 
 # Implementation note: To avoid the server sending us into an
@@ -542,7 +526,7 @@
 urlparts[2] = "/"
 newurl = urlunparse(urlparts)
 
- newurl = urljoin(req.get_full_url(), newurl)
+ newurl = urljoin(req.full_url, newurl)
 
 # XXX Probably want to forget about the state of the current
 # request, although that might interact poorly with other
@@ -557,7 +541,7 @@
 visited = new.redirect_dict = req.redirect_dict
 if (visited.get(newurl, 0) >= self.max_repeats or
 len(visited) >= self.max_redirections):
- raise HTTPError(req.get_full_url(), code,
+ raise HTTPError(req.full_url, code,
 self.inf_msg + msg, headers, fp)
 else:
 visited = new.redirect_dict = req.redirect_dict = {}
@@ -664,7 +648,7 @@
 meth(r, proxy, type))
 
 def proxy_open(self, req, proxy, type):
- orig_type = req.get_type()
+ orig_type = req.type
 proxy_type, user, password, hostport = _parse_proxy(proxy)
 if proxy_type is None:
 proxy_type = orig_type
@@ -811,7 +795,7 @@
 auth_header = 'Authorization'
 
 def http_error_401(self, req, fp, code, msg, headers):
- url = req.get_full_url()
+ url = req.full_url
 return self.http_error_auth_reqed('www-authenticate',
 url, req, headers)
 
@@ -825,7 +809,7 @@
 # authority. Assume there isn't one, since urllib.request does not (and
 # should not, RFC 3986 s. 3.2.1) support requests for URLs containing
 # userinfo.
- authority = req.get_host()
+ authority = req.host
 return self.http_error_auth_reqed('proxy-authenticate',
 authority, req, headers)
 
@@ -864,7 +848,7 @@
 # prompting for the information. Crap. This isn't great
 # but it's better than the current 'repeat until recursion
 # depth exceeded' approach <wink>
- raise HTTPError(req.get_full_url(), 401, "digest auth failed",
+ raise HTTPError(req.full_url, 401, "digest auth failed",
 headers, None)
 else:
 self.retried += 1
@@ -912,20 +896,20 @@
 if H is None:
 return None
 
- user, pw = self.passwd.find_user_password(realm, req.get_full_url())
+ user, pw = self.passwd.find_user_password(realm, req.full_url)
 if user is None:
 return None
 
 # XXX not implemented yet
- if req.has_data():
- entdig = self.get_entity_digest(req.get_data(), chal)
+ if req.data is not None:
+ entdig = self.get_entity_digest(req.data, chal)
 else:
 entdig = None
 
 A1 = "%s:%s:%s" % (user, realm, pw)
 A2 = "%s:%s" % (req.get_method(),
 # XXX selector: what about proxies and full urls
- req.get_selector())
+ req.selector)
 if qop == 'auth':
 self.nonce_count += 1
 ncvalue = '%08x' % self.nonce_count
@@ -941,7 +925,7 @@
 # XXX should the partial digests be encoded too?
 
 base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \
- 'response="%s"' % (user, realm, nonce, req.get_selector(),
+ 'response="%s"' % (user, realm, nonce, req.selector,
 respdig)
 if opaque:
 base += ', opaque="%s"' % opaque
@@ -978,7 +962,7 @@
 handler_order = 490 # before Basic auth
 
 def http_error_401(self, req, fp, code, msg, headers):
- host = urlparse(req.get_full_url())[1]
+ host = urlparse(req.full_url)[1]
 retry = self.http_error_auth_reqed('www-authenticate',
 host, req, headers)
 self.reset_retry_count()
@@ -991,7 +975,7 @@
 handler_order = 490 # before Basic auth
 
 def http_error_407(self, req, fp, code, msg, headers):
- host = req.get_host()
+ host = req.host
 retry = self.http_error_auth_reqed('proxy-authenticate',
 host, req, headers)
 self.reset_retry_count()
@@ -1006,12 +990,12 @@
 self._debuglevel = level
 
 def do_request_(self, request):
- host = request.get_host()
+ host = request.host
 if not host:
 raise URLError('no host given')
 
- if request.has_data(): # POST
- data = request.get_data()
+ if request.data is not None: # POST
+ data = request.data
 if not request.has_header('Content-type'):
 request.add_unredirected_header(
 'Content-type',
@@ -1022,7 +1006,7 @@
 
 sel_host = host
 if request.has_proxy():
- scheme, sel = splittype(request.get_selector())
+ scheme, sel = splittype(request.selector)
 sel_host, sel_path = splithost(sel)
 if not request.has_header('Host'):
 request.add_unredirected_header('Host', sel_host)
@@ -1034,16 +1018,11 @@
 return request
 
 def do_open(self, http_class, req):
- """Return an addinfourl object for the request, using http_class.
+ """Return an HTTPResponse object for the request, using http_class.
 
 http_class must implement the HTTPConnection API from http.client.
- The addinfourl return value is a file-like object. It also
- has methods and attributes including:
- - info(): return a email Message object for the headers
- - geturl(): return the original request URL
- - code: HTTP status code
 """
- host = req.get_host()
+ host = req.host
 if not host:
 raise URLError('no host given')
 
@@ -1061,19 +1040,21 @@
 # So make sure the connection gets closed after the (only)
 # request.
 headers["Connection"] = "close"
- headers = dict(
- (name.title(), val) for name, val in headers.items())
+ headers = dict((name.title(), val) for name, val in headers.items())
 try:
- h.request(req.get_method(), req.get_selector(), req.data, headers)
- r = h.getresponse()
- except socket.error as err: # XXX what error?
+ h.request(req.get_method(), req.selector, req.data, headers)
+ r = h.getresponse() # an HTTPResponse instance
+ except socket.error as err:
 raise URLError(err)
 
-## resp = addinfourl(r.fp, r.msg, req.get_full_url())
- resp = addinfourl(r, r.msg, req.get_full_url())
- resp.code = r.status
- resp.msg = r.reason
- return resp
+ r.url = req.full_url
+ # This line replaces the .msg attribute of the HTTPResponse
+ # with .headers, because urllib clients expect the response to
+ # have the reason in .msg. It would be good to mark this
+ # attribute is deprecated and get then to use info() or
+ # .headers.
+ r.msg = r.reason
+ return r
 
 
 class HTTPHandler(AbstractHTTPHandler):
@@ -1111,7 +1092,7 @@
 
 class UnknownHandler(BaseHandler):
 def unknown_open(self, req):
- type = req.get_type()
+ type = req.type
 raise URLError('unknown url type: %s' % type)
 
 def parse_keqv_list(l):
@@ -1170,7 +1151,7 @@
 class FileHandler(BaseHandler):
 # Use local file or FTP depending on form of URL
 def file_open(self, req):
- url = req.get_selector()
+ url = req.selector
 if url[:2] == '//' and url[2:3] != '/':
 req.type = 'ftp'
 return self.parent.open(req)
@@ -1192,8 +1173,8 @@
 def open_local_file(self, req):
 import email.utils
 import mimetypes
- host = req.get_host()
- file = req.get_selector()
+ host = req.host
+ file = req.selector
 localfile = url2pathname(file)
 try:
 stats = os.stat(localfile)
@@ -1223,7 +1204,7 @@
 def ftp_open(self, req):
 import ftplib
 import mimetypes
- host = req.get_host()
+ host = req.host
 if not host:
 raise URLError('ftp error: no host given')
 host, port = splitport(host)
@@ -1246,7 +1227,7 @@
 host = socket.gethostbyname(host)
 except socket.error as msg:
 raise URLError(msg)
- path, attrs = splitattr(req.get_selector())
+ path, attrs = splitattr(req.selector)
 dirs = path.split('/')
 dirs = list(map(unquote, dirs))
 dirs, file = dirs[:-1], dirs[-1]
@@ -1262,13 +1243,13 @@
 type = value.upper()
 fp, retrlen = fw.retrfile(file, type)
 headers = ""
- mtype = mimetypes.guess_type(req.get_full_url())[0]
+ mtype = mimetypes.guess_type(req.full_url)[0]
 if mtype:
 headers += "Content-type: %s\n" % mtype
 if retrlen is not None and retrlen >= 0:
 headers += "Content-length: %d\n" % retrlen
 headers = email.message_from_string(headers)
- return addinfourl(fp, headers, req.get_full_url())
+ return addinfourl(fp, headers, req.full_url)
 except ftplib.all_errors as msg:
 exc = URLError('ftp error: %s' % msg)
 raise exc.with_traceback(sys.exc_info()[2])
@@ -1581,10 +1562,6 @@
 else:
 auth = None
 http_conn = connection_factory(host)
- # XXX We should fix urllib so that it works with HTTP/1.1.
- http_conn._http_vsn = 10
- http_conn._http_vsn_str = "HTTP/1.0"
-
 headers = {}
 if proxy_auth:
 headers["Proxy-Authorization"] = "Basic %s" % proxy_auth
@@ -2183,18 +2160,18 @@
 """
 proxies = {}
 try:
- import _winreg
+ import winreg
 except ImportError:
 # Std module, so should be around - but you never know!
 return proxies
 try:
- internetSettings = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
+ internetSettings = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
 r'Software\Microsoft\Windows\CurrentVersion\Internet Settings')
- proxyEnable = _winreg.QueryValueEx(internetSettings,
+ proxyEnable = winreg.QueryValueEx(internetSettings,
 'ProxyEnable')[0]
 if proxyEnable:
 # Returned as Unicode but problems if not converted to ASCII
- proxyServer = str(_winreg.QueryValueEx(internetSettings,
+ proxyServer = str(winreg.QueryValueEx(internetSettings,
 'ProxyServer')[0])
 if '=' in proxyServer:
 # Per-protocol settings
@@ -2231,17 +2208,17 @@
 
 def proxy_bypass_registry(host):
 try:
- import _winreg
+ import winreg
 import re
 except ImportError:
 # Std modules, so should be around - but you never know!
 return 0
 try:
- internetSettings = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
+ internetSettings = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
 r'Software\Microsoft\Windows\CurrentVersion\Internet Settings')
- proxyEnable = _winreg.QueryValueEx(internetSettings,
+ proxyEnable = winreg.QueryValueEx(internetSettings,
 'ProxyEnable')[0]
- proxyOverride = str(_winreg.QueryValueEx(internetSettings,
+ proxyOverride = str(winreg.QueryValueEx(internetSettings,
 'ProxyOverride')[0])
 # ^^^^ Returned as Unicode but problems if not converted to ASCII
 except WindowsError:
Modified: python/branches/py3k-short-float-repr/Lib/xmlrpc/client.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/xmlrpc/client.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/xmlrpc/client.py	Sun Apr 5 01:04:14 2009
@@ -1316,7 +1316,7 @@
 transport = Transport(use_datetime=use_datetime)
 self.__transport = transport
 
- self.__encoding = encoding
+ self.__encoding = encoding or 'utf-8'
 self.__verbose = verbose
 self.__allow_none = allow_none
 
@@ -1324,7 +1324,7 @@
 # call a method on the remote server
 
 request = dumps(params, methodname, encoding=self.__encoding,
- allow_none=self.__allow_none)
+ allow_none=self.__allow_none).encode(self.__encoding)
 
 response = self.__transport.request(
 self.__host,
Modified: python/branches/py3k-short-float-repr/Lib/xmlrpc/server.py
==============================================================================
--- python/branches/py3k-short-float-repr/Lib/xmlrpc/server.py	(original)
+++ python/branches/py3k-short-float-repr/Lib/xmlrpc/server.py	Sun Apr 5 01:04:14 2009
@@ -163,7 +163,7 @@
 self.funcs = {}
 self.instance = None
 self.allow_none = allow_none
- self.encoding = encoding
+ self.encoding = encoding or 'utf-8'
 
 def register_instance(self, instance, allow_dotted_names=False):
 """Registers an instance to respond to XML-RPC requests.
@@ -266,7 +266,7 @@
 encoding=self.encoding, allow_none=self.allow_none,
 )
 
- return response
+ return response.encode(self.encoding)
 
 def system_listMethods(self):
 """system.listMethods() => ['add', 'subtract', 'multiple']
@@ -473,8 +473,6 @@
 
 self.end_headers()
 else:
- # 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)))
@@ -551,7 +549,9 @@
 print('Content-Type: text/xml')
 print('Content-Length: %d' % len(response))
 print()
- sys.stdout.write(response)
+ sys.stdout.flush()
+ sys.stdout.buffer.write(response)
+ sys.stdout.buffer.flush()
 
 def handle_get(self):
 """Handle a single HTTP GET request.
@@ -569,11 +569,14 @@
 'message' : message,
 'explain' : explain
 }
+ response = response.encode('utf-8')
 print('Status: %d %s' % (code, message))
- print('Content-Type: text/html')
+ print('Content-Type: %s' % http.server.DEFAULT_ERROR_CONTENT_TYPE)
 print('Content-Length: %d' % len(response))
 print()
- sys.stdout.write(response)
+ sys.stdout.flush()
+ sys.stdout.buffer.write(response)
+ sys.stdout.buffer.flush()
 
 def handle_request(self, request_text = None):
 """Handle a single XML-RPC request passed through a CGI post method.
@@ -588,8 +591,12 @@
 self.handle_get()
 else:
 # POST data is normally available through stdin
+ try:
+ length = int(os.environ.get('CONTENT_LENGTH', None))
+ except (ValueError, TypeError):
+ length = -1
 if request_text is None:
- request_text = sys.stdin.read()
+ request_text = sys.stdin.read(length)
 
 self.handle_xmlrpc(request_text)
 
@@ -810,12 +817,12 @@
 self.report_404()
 return
 
- response = self.server.generate_html_documentation()
+ response = self.server.generate_html_documentation().encode('utf-8')
 self.send_response(200)
 self.send_header("Content-type", "text/html")
 self.send_header("Content-length", str(len(response)))
 self.end_headers()
- self.wfile.write(response.encode())
+ self.wfile.write(response)
 
 # shut down the connection
 self.wfile.flush()
@@ -848,12 +855,14 @@
 documentation.
 """
 
- response = self.generate_html_documentation()
+ response = self.generate_html_documentation().encode('utf-8')
 
 print('Content-Type: text/html')
 print('Content-Length: %d' % len(response))
 print()
- sys.stdout.write(response)
+ sys.stdout.flush()
+ sys.stdout.buffer.write(response)
+ sys.stdout.buffer.flush()
 
 def __init__(self):
 CGIXMLRPCRequestHandler.__init__(self)
Modified: python/branches/py3k-short-float-repr/Mac/BuildScript/README.txt
==============================================================================
--- python/branches/py3k-short-float-repr/Mac/BuildScript/README.txt	(original)
+++ python/branches/py3k-short-float-repr/Mac/BuildScript/README.txt	Sun Apr 5 01:04:14 2009
@@ -37,6 +37,17 @@
 * When done the script will tell you where the DMG image is (by default
 somewhere in ``/tmp/_py``).
 
+Building a 4-way universal installer
+....................................
+
+It is also possible to build a 4-way universal installer that runs on 
+OSX Leopard or later::
+
+ $ ./build-installer.py --dep-target=10.5 --universal-archs=all --sdk=/
+
+This requires that the deployment target is 10.5 (or later), and hence
+also that your building on at least OSX 10.5.
+
 Testing
 -------
 
Modified: python/branches/py3k-short-float-repr/Mac/BuildScript/build-installer.py
==============================================================================
--- python/branches/py3k-short-float-repr/Mac/BuildScript/build-installer.py	(original)
+++ python/branches/py3k-short-float-repr/Mac/BuildScript/build-installer.py	Sun Apr 5 01:04:14 2009
@@ -2,7 +2,8 @@
 """
 This script is used to build the "official unofficial" universal build on
 Mac OS X. It requires Mac OS X 10.4, Xcode 2.2 and the 10.4u SDK to do its
-work.
+work. 64-bit or four-way universal builds require at least OS X 10.5 and
+the 10.5 SDK.
 
 Please ensure that this script keeps working with Python 2.3, to avoid
 bootstrap issues (/usr/bin/python is Python 2.3 on OSX 10.4)
@@ -63,7 +64,15 @@
 SDKPATH = "/Developer/SDKs/MacOSX10.4u.sdk"
 #SDKPATH = "/"
 
-ARCHLIST = ('i386', 'ppc',)
+universal_opts_map = { '32-bit': ('i386', 'ppc',),
+ '64-bit': ('x86_64', 'ppc64',),
+ 'all': ('i386', 'ppc', 'x86_64', 'ppc64',) }
+
+UNIVERSALOPTS = tuple(universal_opts_map.keys())
+
+UNIVERSALARCHS = '32-bit'
+
+ARCHLIST = universal_opts_map[UNIVERSALARCHS]
 
 # Source directory (asume we're in Mac/BuildScript)
 SRCDIR = os.path.dirname(
@@ -72,6 +81,9 @@
 os.path.abspath(__file__
 ))))
 
+# $MACOSX_DEPLOYMENT_TARGET -> minimum OS X level
+DEPTARGET = '10.3'
+
 USAGE = textwrap.dedent("""\
 Usage: build_python [options]
 
@@ -82,62 +94,67 @@
 --third-party=DIR: Store third-party sources here (default: %(DEPSRC)r)
 --sdk-path=DIR: Location of the SDK (default: %(SDKPATH)r)
 --src-dir=DIR: Location of the Python sources (default: %(SRCDIR)r)
+ --dep-target=10.n OS X deployment target (default: %(DEPTARGET)r)
+ --universal-archs=x universal architectures (options: %(UNIVERSALOPTS)r, default: %(UNIVERSALARCHS)r)
 """)% globals()
 
 
 # Instructions for building libraries that are necessary for building a
 # batteries included python.
-LIBRARY_RECIPES = [
- dict(
- name="Bzip2 1.0.4",
- url="http://www.bzip.org/1.0.4/bzip2-1.0.4.tar.gz",
- checksum='fc310b254f6ba5fbb5da018f04533688',
- configure=None,
- install='make install PREFIX=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%(
- shellQuote(os.path.join(WORKDIR, 'libraries')),
- ' -arch '.join(ARCHLIST),
- SDKPATH,
- ),
- ),
- dict(
- name="ZLib 1.2.3",
- url="http://www.gzip.org/zlib/zlib-1.2.3.tar.gz",
- checksum='debc62758716a169df9f62e6ab2bc634',
- configure=None,
- install='make install prefix=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%(
- shellQuote(os.path.join(WORKDIR, 'libraries')),
- ' -arch '.join(ARCHLIST),
- SDKPATH,
- ),
- ),
- dict(
- # Note that GNU readline is GPL'd software
- name="GNU Readline 5.1.4",
- url="http://ftp.gnu.org/pub/gnu/readline/readline-5.1.tar.gz" ,
- checksum='7ee5a692db88b30ca48927a13fd60e46',
- patchlevel='0',
- patches=[
- # The readline maintainers don't do actual micro releases, but
- # just ship a set of patches.
- 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-001',
- 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-002',
- 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-003',
- 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-004',
- ]
- ),
-
- dict(
- name="SQLite 3.6.11",
- url="http://www.sqlite.org/sqlite-3.6.11.tar.gz",
- checksum='7ebb099696ab76cc6ff65dd496d17858',
- configure_pre=[
- '--enable-threadsafe',
- '--enable-tempstore',
- '--enable-shared=no',
- '--enable-static=yes',
- '--disable-tcl',
- ]
- ),
+# [The recipes are defined here for convenience but instantiated later after
+# command line options have been processed.]
+def library_recipes():
+ return [
+ dict(
+ name="Bzip2 1.0.4",
+ url="http://www.bzip.org/1.0.4/bzip2-1.0.4.tar.gz",
+ checksum='fc310b254f6ba5fbb5da018f04533688',
+ configure=None,
+ install='make install PREFIX=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%(
+ shellQuote(os.path.join(WORKDIR, 'libraries')),
+ ' -arch '.join(ARCHLIST),
+ SDKPATH,
+ ),
+ ),
+ dict(
+ name="ZLib 1.2.3",
+ url="http://www.gzip.org/zlib/zlib-1.2.3.tar.gz",
+ checksum='debc62758716a169df9f62e6ab2bc634',
+ configure=None,
+ install='make install prefix=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%(
+ shellQuote(os.path.join(WORKDIR, 'libraries')),
+ ' -arch '.join(ARCHLIST),
+ SDKPATH,
+ ),
+ ),
+ dict(
+ # Note that GNU readline is GPL'd software
+ name="GNU Readline 5.1.4",
+ url="http://ftp.gnu.org/pub/gnu/readline/readline-5.1.tar.gz" ,
+ checksum='7ee5a692db88b30ca48927a13fd60e46',
+ patchlevel='0',
+ patches=[
+ # The readline maintainers don't do actual micro releases, but
+ # just ship a set of patches.
+ 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-001',
+ 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-002',
+ 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-003',
+ 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-004',
+ ]
+ ),
+
+ dict(
+ name="SQLite 3.6.11",
+ url="http://www.sqlite.org/sqlite-3.6.11.tar.gz",
+ checksum='7ebb099696ab76cc6ff65dd496d17858',
+ configure_pre=[
+ '--enable-threadsafe',
+ '--enable-tempstore',
+ '--enable-shared=no',
+ '--enable-static=yes',
+ '--disable-tcl',
+ ]
+ ),
 
 dict(
 name="NCurses 5.5",
@@ -170,7 +187,6 @@
 ),
 ]
 
-
 # Instructions for building packages inside the .mpkg.
 PKG_RECIPES = [
 dict(
@@ -205,8 +221,8 @@
 source="/usr/local/bin",
 readme="""\
 This package installs the unix tools in /usr/local/bin for
- compatibility with older releases of MacPython. This package
- is not necessary to use MacPython.
+ compatibility with older releases of Python. This package
+ is not necessary to use Python.
 """,
 required=False,
 selected='unselected',
@@ -231,7 +247,7 @@
 long_name="Shell profile updater",
 readme="""\
 This packages updates your shell profile to make sure that
- the MacPython tools are found by your shell in preference of
+ the Python tools are found by your shell in preference of
 the system provided Python tools.
 
 If you don't install this package you'll have to add
@@ -321,14 +337,16 @@
 """
 Parse arguments and update global settings.
 """
- global WORKDIR, DEPSRC, SDKPATH, SRCDIR
+ global WORKDIR, DEPSRC, SDKPATH, SRCDIR, DEPTARGET
+ global UNIVERSALOPTS, UNIVERSALARCHS, ARCHLIST
 
 if args is None:
 args = sys.argv[1:]
 
 try:
 options, args = getopt.getopt(args, '?hb',
- [ 'build-dir=', 'third-party=', 'sdk-path=' , 'src-dir='])
+ [ 'build-dir=', 'third-party=', 'sdk-path=' , 'src-dir=',
+ 'dep-target=', 'universal-archs=', 'help' ])
 except getopt.error, msg:
 print msg
 sys.exit(1)
@@ -338,7 +356,7 @@
 sys.exit(1)
 
 for k, v in options:
- if k in ('-h', '-?'):
+ if k in ('-h', '-?', '--help'):
 print USAGE
 sys.exit(0)
 
@@ -354,6 +372,16 @@
 elif k in ('--src-dir',):
 SRCDIR=v
 
+ elif k in ('--dep-target', ):
+ DEPTARGET=v
+
+ elif k in ('--universal-archs', ):
+ if v in UNIVERSALOPTS:
+ UNIVERSALARCHS = v
+ ARCHLIST = universal_opts_map[UNIVERSALARCHS]
+ else:
+ raise NotImplementedError, v
+
 else:
 raise NotImplementedError, k
 
@@ -366,7 +394,9 @@
 print " * Source directory:", SRCDIR
 print " * Build directory: ", WORKDIR
 print " * SDK location: ", SDKPATH
- print " * third-party source:", DEPSRC
+ print " * Third-party source:", DEPSRC
+ print " * Deployment target:", DEPTARGET
+ print " * Universal architectures:", ARCHLIST
 print ""
 
 
@@ -476,6 +506,7 @@
 print "Using local copy of %s"%(name,)
 
 else:
+ print "Did not find local copy of %s"%(name,)
 print "Downloading %s"%(name,)
 downloadURL(url, sourceArchive)
 print "Archive for %s stored as %s"%(name, sourceArchive)
@@ -566,7 +597,7 @@
 os.makedirs(os.path.join(universal, 'usr', 'local', 'lib'))
 os.makedirs(os.path.join(universal, 'usr', 'local', 'include'))
 
- for recipe in LIBRARY_RECIPES:
+ for recipe in library_recipes():
 buildRecipe(recipe, universal, ARCHLIST)
 
 
@@ -590,7 +621,7 @@
 
 
 def buildPython():
- print "Building a universal python"
+ print "Building a universal python for %s architectures" % UNIVERSALARCHS
 
 buildDir = os.path.join(WORKDIR, '_bld', 'python')
 rootDir = os.path.join(WORKDIR, '_root')
@@ -613,10 +644,19 @@
 # several paths.
 version = getVersion()
 
+ # Since the extra libs are not in their installed framework location
+ # during the build, augment the library path so that the interpreter
+ # will find them during its extension import sanity checks.
+ os.environ['DYLD_LIBRARY_PATH'] = os.path.join(WORKDIR,
+ 'libraries', 'usr', 'local', 'lib')
 print "Running configure..."
- runCommand("%s -C --enable-framework --enable-universalsdk=%s LDFLAGS='-g -L%s/libraries/usr/local/lib' OPT='-g -O3 -I%s/libraries/usr/local/include' 2>&1"%(
- shellQuote(os.path.join(SRCDIR, 'configure')),
- shellQuote(SDKPATH), shellQuote(WORKDIR)[1:-1],
+ runCommand("%s -C --enable-framework --enable-universalsdk=%s "
+ "--with-universal-archs=%s --with-computed-gotos "
+ "LDFLAGS='-g -L%s/libraries/usr/local/lib' "
+ "OPT='-g -O3 -I%s/libraries/usr/local/include' 2>&1"%(
+ shellQuote(os.path.join(SRCDIR, 'configure')), shellQuote(SDKPATH),
+ UNIVERSALARCHS,
+ shellQuote(WORKDIR)[1:-1],
 shellQuote(WORKDIR)[1:-1]))
 
 print "Running make"
@@ -630,6 +670,7 @@
 runCommand("make frameworkinstallextras DESTDIR=%s"%(
 shellQuote(rootDir)))
 
+ del os.environ['DYLD_LIBRARY_PATH']
 print "Copying required shared libraries"
 if os.path.exists(os.path.join(WORKDIR, 'libraries', 'Library')):
 runCommand("mv %s/* %s"%(
@@ -704,7 +745,7 @@
 data = fileContents(inPath)
 data = data.replace('$FULL_VERSION', getFullVersion())
 data = data.replace('$VERSION', getVersion())
- data = data.replace('$MACOSX_DEPLOYMENT_TARGET', '10.3 or later')
+ data = data.replace('$MACOSX_DEPLOYMENT_TARGET', ''.join((DEPTARGET, ' or later')))
 data = data.replace('$ARCHITECTURES', "i386, ppc")
 data = data.replace('$INSTALL_SIZE', installSize())
 
@@ -784,9 +825,9 @@
 vers = getFullVersion()
 major, minor = map(int, getVersion().split('.', 2))
 pl = Plist(
- CFBundleGetInfoString="MacPython.%s %s"%(pkgname, vers,),
- CFBundleIdentifier='org.python.MacPython.%s'%(pkgname,),
- CFBundleName='MacPython.%s'%(pkgname,),
+ CFBundleGetInfoString="Python.%s %s"%(pkgname, vers,),
+ CFBundleIdentifier='org.python.Python.%s'%(pkgname,),
+ CFBundleName='Python.%s'%(pkgname,),
 CFBundleShortVersionString=vers,
 IFMajorVersion=major,
 IFMinorVersion=minor,
@@ -807,7 +848,7 @@
 
 pl = Plist(
 IFPkgDescriptionDescription=readme,
- IFPkgDescriptionTitle=recipe.get('long_name', "MacPython.%s"%(pkgname,)),
+ IFPkgDescriptionTitle=recipe.get('long_name', "Python.%s"%(pkgname,)),
 IFPkgDescriptionVersion=vers,
 )
 writePlist(pl, os.path.join(packageContents, 'Resources', 'Description.plist'))
@@ -822,9 +863,9 @@
 major, minor = map(int, getVersion().split('.', 2))
 
 pl = Plist(
- CFBundleGetInfoString="MacPython %s"%(vers,),
- CFBundleIdentifier='org.python.MacPython',
- CFBundleName='MacPython',
+ CFBundleGetInfoString="Python %s"%(vers,),
+ CFBundleIdentifier='org.python.Python',
+ CFBundleName='Python',
 CFBundleShortVersionString=vers,
 IFMajorVersion=major,
 IFMinorVersion=minor,
@@ -858,7 +899,7 @@
 shutil.rmtree(outdir)
 os.mkdir(outdir)
 
- pkgroot = os.path.join(outdir, 'MacPython.mpkg', 'Contents')
+ pkgroot = os.path.join(outdir, 'Python.mpkg', 'Contents')
 pkgcontents = os.path.join(pkgroot, 'Packages')
 os.makedirs(pkgcontents)
 for recipe in PKG_RECIPES:
@@ -875,7 +916,7 @@
 
 makeMpkgPlist(os.path.join(pkgroot, 'Info.plist'))
 pl = Plist(
- IFPkgDescriptionTitle="Universal MacPython",
+ IFPkgDescriptionTitle="Python",
 IFPkgDescriptionVersion=getVersion(),
 )
 
@@ -915,10 +956,32 @@
 imagepath = imagepath + '.dmg'
 
 os.mkdir(outdir)
- runCommand("hdiutil create -volname 'Universal MacPython %s' -srcfolder %s %s"%(
- getFullVersion(),
+ volname='Python %s'%(getFullVersion())
+ runCommand("hdiutil create -format UDRW -volname %s -srcfolder %s %s"%(
+ shellQuote(volname),
 shellQuote(os.path.join(WORKDIR, 'installer')),
- shellQuote(imagepath)))
+ shellQuote(imagepath + ".tmp.dmg" )))
+
+
+ if not os.path.exists(os.path.join(WORKDIR, "mnt")):
+ os.mkdir(os.path.join(WORKDIR, "mnt"))
+ runCommand("hdiutil attach %s -mountroot %s"%(
+ shellQuote(imagepath + ".tmp.dmg"), shellQuote(os.path.join(WORKDIR, "mnt"))))
+
+ # Custom icon for the DMG, shown when the DMG is mounted.
+ shutil.copy("../Icons/Disk Image.icns",
+ os.path.join(WORKDIR, "mnt", volname, ".VolumeIcon.icns"))
+ runCommand("/Developer/Tools/SetFile -a C %s/"%(
+ shellQuote(os.path.join(WORKDIR, "mnt", volname)),))
+
+ runCommand("hdiutil detach %s"%(shellQuote(os.path.join(WORKDIR, "mnt", volname))))
+
+ setIcon(imagepath + ".tmp.dmg", "../Icons/Disk Image.icns")
+ runCommand("hdiutil convert %s -format UDZO -o %s"%(
+ shellQuote(imagepath + ".tmp.dmg"), shellQuote(imagepath)))
+ setIcon(imagepath, "../Icons/Disk Image.icns")
+
+ os.unlink(imagepath + ".tmp.dmg")
 
 return imagepath
 
@@ -946,7 +1009,7 @@
 parseOptions()
 checkEnvironment()
 
- os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
+ os.environ['MACOSX_DEPLOYMENT_TARGET'] = DEPTARGET
 
 if os.path.exists(WORKDIR):
 shutil.rmtree(WORKDIR)
@@ -957,7 +1020,18 @@
 
 # Now build python itself
 buildPython()
+
+ # And then build the documentation
+ # Remove the Deployment Target from the shell
+ # environment, it's no longer needed and
+ # an unexpected build target can cause problems
+ # when Sphinx and its dependencies need to
+ # be (re-)installed.
+ del os.environ['MACOSX_DEPLOYMENT_TARGET']
 buildPythonDocs()
+
+
+ # Prepare the applications folder
 fn = os.path.join(WORKDIR, "_root", "Applications",
 "Python %s"%(getVersion(),), "Update Shell Profile.command")
 patchScript("scripts/postflight.patch-profile", fn)
@@ -982,13 +1056,6 @@
 print >> fp, "# By:", pwd.getpwuid(os.getuid()).pw_gecos
 fp.close()
 
- # Custom icon for the DMG, shown when the DMG is mounted.
- # XXX: Code is diabled because it doesn't actually work :-(
-# shutil.copy("../Icons/Disk Image.icns",
-# os.path.join(WORKDIR, "installer", ".VolumeIcon.icns"))
-# os.system("/Developer/Tools/SetFile -a C %s"%(
-# os.path.join(WORKDIR, "installer", ".VolumeIcon.icns")))
- setIcon(os.path.join(WORKDIR, "installer"), "../Icons/Disk Image.icns")
 
 
 # And copy it to a DMG
Modified: python/branches/py3k-short-float-repr/Mac/BuildScript/resources/ReadMe.txt
==============================================================================
--- python/branches/py3k-short-float-repr/Mac/BuildScript/resources/ReadMe.txt	(original)
+++ python/branches/py3k-short-float-repr/Mac/BuildScript/resources/ReadMe.txt	Sun Apr 5 01:04:14 2009
@@ -19,9 +19,11 @@
 that open up specific Macintosh technologies to Python programs.
 
 The installer puts the applications in "Python $VERSION" 
-in your Applications folder, command-line tools in
-/usr/local/bin and the underlying machinery in
-$PYTHONFRAMEWORKINSTALLDIR.
+in your Applications folder, and the underlying machinery in
+$PYTHONFRAMEWORKINSTALLDIR. It can optionally place
+links to the command-line tools in /usr/local as well,
+by default you have to add the "bin" directory inside
+the framework to you shell's search path.
 
 More information on MacPython can be found at
 http://www.python.org/download/mac/.
Modified: python/branches/py3k-short-float-repr/Mac/Makefile.in
==============================================================================
--- python/branches/py3k-short-float-repr/Mac/Makefile.in	(original)
+++ python/branches/py3k-short-float-repr/Mac/Makefile.in	Sun Apr 5 01:04:14 2009
@@ -14,6 +14,7 @@
 LDFLAGS=@LDFLAGS@
 FRAMEWORKUNIXTOOLSPREFIX=@FRAMEWORKUNIXTOOLSPREFIX@
 PYTHONFRAMEWORK=@PYTHONFRAMEWORK@
+PYTHONFRAMEWORKIDENTIFIER=@PYTHONFRAMEWORKIDENTIFIER@
 
 
 # These are normally glimpsed from the previous set
@@ -206,6 +207,12 @@
 		done; \
 	done
 	$(INSTALL_PROGRAM) $(STRIPFLAG) $(BUILDPYTHON) "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)"
+	sed -e "s!%bundleid%!$(PYTHONFRAMEWORKIDENTIFIER)!g" \
+		-e "s!%version%!`$(RUNSHARED) $(BUILDPYTHON) \
+		-c 'import platform; print(platform.python_version())'`!g" \
+		< "$(DESTDIR)$(APPINSTALLDIR)/Contents/Info.plist.in" \
+		> "$(DESTDIR)$(APPINSTALLDIR)/Contents/Info.plist"
+	rm "$(DESTDIR)$(APPINSTALLDIR)/Contents/Info.plist.in"
 
 install_Python4way: install_Python
 	lipo -extract i386 -extract ppc7400 -output "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)-32" "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)"
Modified: python/branches/py3k-short-float-repr/Mac/PythonLauncher/FileSettings.m
==============================================================================
--- python/branches/py3k-short-float-repr/Mac/PythonLauncher/FileSettings.m	(original)
+++ python/branches/py3k-short-float-repr/Mac/PythonLauncher/FileSettings.m	Sun Apr 5 01:04:14 2009
@@ -267,14 +267,14 @@
 	 [script length]-[[script lastPathComponent] length]];
 
 if (honourhashbang &&
- (fp=fopen([script cString], "r")) &&
+ (fp=fopen([script fileSystemRepresentation], "r")) &&
 fgets(hashbangbuf, sizeof(hashbangbuf), fp) &&
 strncmp(hashbangbuf, "#!", 2) == 0 &&
 (p=strchr(hashbangbuf, '\n'))) {
 *p = '0円';
 p = hashbangbuf + 2;
 while (*p == ' ') p++;
- cur_interp = [NSString stringWithCString: p];
+ cur_interp = [NSString stringWithUTF8String: p];
 }
 if (!cur_interp)
 cur_interp = interpreter;
Modified: python/branches/py3k-short-float-repr/Mac/Resources/app/Info.plist.in
==============================================================================
--- python/branches/py3k-short-float-repr/Mac/Resources/app/Info.plist.in	(original)
+++ python/branches/py3k-short-float-repr/Mac/Resources/app/Info.plist.in	Sun Apr 5 01:04:14 2009
@@ -20,7 +20,7 @@
 	<key>CFBundleExecutable</key>
 	<string>Python</string>
 	<key>CFBundleGetInfoString</key>
-	<string>@VERSION@, (c) 2004 Python Software Foundation.</string>
+	<string>%version%, (c) 2004-2009 Python Software Foundation.</string>
 	<key>CFBundleHelpBookFolder</key>
 	<array>
 		<string>Documentation</string>
@@ -33,21 +33,21 @@
 	<key>CFBundleIconFile</key>
 	<string>PythonInterpreter.icns</string>
 	<key>CFBundleIdentifier</key>
-	<string>@PYTHONFRAMEWORKIDENTIFIER at .app</string>
+	<string>%bundleid%</string>
 	<key>CFBundleInfoDictionaryVersion</key>
 	<string>6.0</string>
 	<key>CFBundleLongVersionString</key>
-	<string>@VERSION@, (c) 2004-2008 Python Software Foundation.</string>
+	<string>%version%, (c) 2004-2009 Python Software Foundation.</string>
 	<key>CFBundleName</key>
 	<string>Python</string>
 	<key>CFBundlePackageType</key>
 	<string>APPL</string>
 	<key>CFBundleShortVersionString</key>
-	<string>@VERSION@</string>
+	<string>%version%</string>
 	<key>CFBundleSignature</key>
 	<string>PytX</string>
 	<key>CFBundleVersion</key>
-	<string>@VERSION@</string>
+	<string>%version%</string>
 	<key>CSResourcesFileMapped</key>
 	<true/>
 	<key>LSRequiresCarbon</key>
Modified: python/branches/py3k-short-float-repr/Makefile.pre.in
==============================================================================
--- python/branches/py3k-short-float-repr/Makefile.pre.in	(original)
+++ python/branches/py3k-short-float-repr/Makefile.pre.in	Sun Apr 5 01:04:14 2009
@@ -193,15 +193,16 @@
 # Used of signalmodule.o is not available
 SIGNAL_OBJS=	@SIGNAL_OBJS@
 
-IO_H=		Modules/_iomodule.h
+IO_H=		Modules/_io/_iomodule.h
 
 IO_OBJS=	\
-		Modules/io.o \
-		Modules/_iobase.o \
-		Modules/_fileio.o \
-		Modules/_bufferedio.o \
-		Modules/_textio.o \
-		Modules/_bytesio.o
+		Modules/_io/_iomodule.o \
+		Modules/_io/iobase.o \
+		Modules/_io/fileio.o \
+		Modules/_io/bufferedio.o \
+		Modules/_io/textio.o \
+		Modules/_io/bytesio.o \
+		Modules/_io/stringio.o
 
 ##########################################################################
 # Grammar
Modified: python/branches/py3k-short-float-repr/Misc/ACKS
==============================================================================
--- python/branches/py3k-short-float-repr/Misc/ACKS	(original)
+++ python/branches/py3k-short-float-repr/Misc/ACKS	Sun Apr 5 01:04:14 2009
@@ -167,6 +167,7 @@
 Raghuram Devarakonda
 Toby Dickenson
 Mark Dickinson
+Jack Diederich
 Humberto Diogenes
 Yves Dionne
 Daniel Dittmar
@@ -257,6 +258,7 @@
 Jonathan Giddy
 Johannes Gijsbers
 Michael Gilfix
+Tim Golden
 Chris Gonnerman
 David Goodger
 Hans de Graaff
@@ -411,6 +413,7 @@
 Inyeol Lee
 Thomas Lee
 Christopher Lee
+Tennessee Leeuwenburg
 Luc Lefebvre
 Kip Lehman
 Joerg Lehmann
@@ -480,6 +483,7 @@
 Chad Miller
 Jay T. Miller
 Roman Milner
+Andrii V. Mishkovskyi 
 Dustin J. Mitchell
 Dom Mitchell
 Doug Moen
@@ -490,6 +494,8 @@
 Sjoerd Mullender
 Sape Mullender
 Michael Muller
+R. David Murray
+Piotr Meyer
 John Nagle
 Takahiro Nakayama
 Travers Naran
@@ -686,7 +692,9 @@
 Nathan Sullivan
 Mark Summerfield
 Hisao Suzuki
+Andrew Svetlov
 Kalle Svensson
+Andrew Svetlov
 Paul Swartz
 Thenault Sylvain
 Geoff Talvola
@@ -792,4 +800,3 @@
 Uwe Zessin
 Tarek ZiadŽ
 Peter Åstrand
-Jesse Noller
Modified: python/branches/py3k-short-float-repr/Misc/NEWS
==============================================================================
--- python/branches/py3k-short-float-repr/Misc/NEWS	(original)
+++ python/branches/py3k-short-float-repr/Misc/NEWS	Sun Apr 5 01:04:14 2009
@@ -7,13 +7,33 @@
 What's New in Python 3.1 alpha 2?
 =================================
 
-*Release date: XXX*
+*Release date: 2009年4月4日*
 
 Core and Builtins
 -----------------
 
+- Implement PEP 378, Format Specifier for Thousands Separator, for
+ integers.
+
+- Issue #5666: Py_BuildValue's 'c' code should create byte strings.
+
+- Issue #5499: The 'c' code for argument parsing functions now only accepts a
+ byte, and the 'C' code only accepts a unicode character.
+
+- Issue #1665206: Remove the last eager import in _warnings.c and make it lazy.
+
+- Fix a segfault when running test_exceptions with coverage, caused by
+ insufficient checks in accessors of Exception.__context__.
+
+- Issue #5604: non-ASCII characters in module name passed to
+ imp.find_module() were converted to UTF-8 while the path is
+ converted to the default filesystem encoding, causing nonsense.
+
 - Issue #5126: str.isprintable() returned False for space characters.
 
+- Issue #4865: On MacOSX /Library/Python/2.7/site-packages is added to
+ the end sys.path, for compatibility with the system install of Python.
+
 - Issue #4688: Add a heuristic so that tuples and dicts containing only
 untrackable objects are not tracked by the garbage collector. This can
 reduce the size of collections and therefore the garbage collection overhead
@@ -40,9 +60,43 @@
 - Issue #5392: when a very low recursion limit was set, the interpreter would
 abort with a fatal error after the recursion limit was hit twice.
 
+- Issue #3845: In PyRun_SimpleFileExFlags avoid invalid memory access with
+ short file names.
+
+- Py_DECREF: Add `do { ... } while (0)' to avoid compiler warnings.
+
 Library
 -------
 
+- Issue 2625: added missing items() call to the for loop in
+ mailbox.MH.get_message().
+
+- Issue #5640: Fix _multibytecodec so that CJK codecs don't repeat
+ error substitutions from non-strict codec error callbacks in
+ incrementalencoder and StreamWriter.
+
+- Issue #5656: Fix the coverage reporting when running the test suite with
+ the -T argument.
+
+- Issue #5647: MutableSet.__iand__() no longer mutates self during iteration.
+
+- Issue #5624: Fix the _winreg module name still used in several modules.
+
+- Issue #5628: Fix io.TextIOWrapper.read() with a unreadable buffer.
+
+- Issue #5619: Multiprocessing children disobey the debug flag and causes
+ popups on windows buildbots. Patch applied to work around this issue.
+
+- Issue #5400: Added patch for multiprocessing on netbsd compilation/support
+
+- Issue #5387: Fixed mmap.move crash by integer overflow.
+
+- Issue #5261: Patch multiprocessing's semaphore.c to support context
+ manager use: "with multiprocessing.Lock()" works now.
+
+- Issue #5236: Change time.strptime() to only take strings. Didn't work with
+ bytes already but the failure was non-obvious.
+
 - Issue #5177: Multiprocessing's SocketListener class now uses
 socket.SO_REUSEADDR on all connections so that the user no longer needs
 to wait 120 seconds for the socket to expire.
@@ -75,6 +129,8 @@
 Extension Modules
 -----------------
 
+- Issue #5391: mmap now deals exclusively with bytes.
+
 - Issue #5463: In struct module, remove deprecated overflow wrapping
 when packing an integer: struct.pack('=L', -1) now raises
 struct.error instead of returning b'\xff\xff\xff\xff'. The
@@ -259,6 +315,17 @@
 Library
 -------
 
+- Issue #1665206 (partially): Move imports in cgitb to the top of the module
+ instead of performing them in functions. Helps prevent import deadlocking in
+ threads.
+
+- Issue #2522: locale.format now checks its first argument to ensure it has
+ been passed only one pattern, avoiding mysterious errors where it appeared
+ that it was failing to do localization.
+
+- Issue #5583: Added optional Extensions in Distutils. Initial patch by Georg
+ Brandl.
+
 - Issue #1222: locale.format() bug when the thousands separator is a space
 character.
 
@@ -694,9 +761,15 @@
 buffer.
 
 
+- Issue #5228: Make functools.partial objects can now be pickled.
+
 Tests
 -----
 
+- regrtest no longer treats ImportError as equivalent to SkipTest. Imports
+ that should cause a test to be skipped are now done using import_module 
+ from test support, which does the conversion.
+
 - Issue #5083: New 'gui' resource for regrtest.
 
 
Modified: python/branches/py3k-short-float-repr/Misc/RPM/python-3.1.spec
==============================================================================
--- python/branches/py3k-short-float-repr/Misc/RPM/python-3.1.spec	(original)
+++ python/branches/py3k-short-float-repr/Misc/RPM/python-3.1.spec	Sun Apr 5 01:04:14 2009
@@ -34,7 +34,7 @@
 
 %define name python
 #--start constants--
-%define version 3.1a1
+%define version 3.1a2
 %define libver 3.1
 #--end constants--
 %define release 1pydotorg
Modified: python/branches/py3k-short-float-repr/Modules/Setup.dist
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/Setup.dist	(original)
+++ python/branches/py3k-short-float-repr/Modules/Setup.dist	Sun Apr 5 01:04:14 2009
@@ -114,7 +114,7 @@
 _weakref _weakref.c		# weak references
 
 # Standard I/O baseline
-_io io.c _iobase.c _fileio.c _bytesio.c _bufferedio.c _textio.c _stringio.c
+_io -I$(srcdir)/Modules/_io _io/_iomodule.c _io/iobase.c _io/fileio.c _io/bytesio.c _io/bufferedio.c _io/textio.c _io/stringio.c
 
 # The zipimport module is always imported at startup. Having it as a
 # builtin module avoids some bootstrapping problems and reduces overhead.
Deleted: python/branches/py3k-short-float-repr/Modules/_bufferedio.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/_bufferedio.c	Sun Apr 5 01:04:14 2009
+++ (empty file)
@@ -1,2139 +0,0 @@
-/*
- An implementation of Buffered I/O as defined by PEP 3116 - "New I/O"
- 
- Classes defined here: BufferedIOBase, BufferedReader, BufferedWriter,
- BufferedRandom.
- 
- Written by Amaury Forgeot d'Arc and Antoine Pitrou
-*/
-
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "structmember.h"
-#include "pythread.h"
-#include "_iomodule.h"
-
-/*
- * BufferedIOBase class, inherits from IOBase.
- */
-PyDoc_STRVAR(BufferedIOBase_doc,
- "Base class for buffered IO objects.\n"
- "\n"
- "The main difference with RawIOBase is that the read() method\n"
- "supports omitting the size argument, and does not have a default\n"
- "implementation that defers to readinto().\n"
- "\n"
- "In addition, read(), readinto() and write() may raise\n"
- "BlockingIOError if the underlying raw stream is in non-blocking\n"
- "mode and not ready; unlike their raw counterparts, they will never\n"
- "return None.\n"
- "\n"
- "A typical implementation should not inherit from a RawIOBase\n"
- "implementation, but wrap one.\n"
- );
-
-static PyObject *
-BufferedIOBase_readinto(PyObject *self, PyObject *args)
-{
- Py_buffer buf;
- Py_ssize_t len;
- PyObject *data;
-
- if (!PyArg_ParseTuple(args, "w*:readinto", &buf)) {
- return NULL;
- }
-
- data = PyObject_CallMethod(self, "read", "n", buf.len);
- if (data == NULL)
- goto error;
-
- if (!PyBytes_Check(data)) {
- Py_DECREF(data);
- PyErr_SetString(PyExc_TypeError, "read() should return bytes");
- goto error;
- }
-
- len = Py_SIZE(data);
- memcpy(buf.buf, PyBytes_AS_STRING(data), len);
-
- PyBuffer_Release(&buf);
- Py_DECREF(data);
-
- return PyLong_FromSsize_t(len);
-
- error:
- PyBuffer_Release(&buf);
- return NULL;
-}
-
-static PyObject *
-BufferedIOBase_unsupported(const char *message)
-{
- PyErr_SetString(IO_STATE->unsupported_operation, message);
- return NULL;
-}
-
-PyDoc_STRVAR(BufferedIOBase_read_doc,
- "Read and return up to n bytes.\n"
- "\n"
- "If the argument is omitted, None, or negative, reads and\n"
- "returns all data until EOF.\n"
- "\n"
- "If the argument is positive, and the underlying raw stream is\n"
- "not 'interactive', multiple raw reads may be issued to satisfy\n"
- "the byte count (unless EOF is reached first). But for\n"
- "interactive raw streams (as well as sockets and pipes), at most\n"
- "one raw read will be issued, and a short result does not imply\n"
- "that EOF is imminent.\n"
- "\n"
- "Returns an empty bytes object on EOF.\n"
- "\n"
- "Returns None if the underlying raw stream was open in non-blocking\n"
- "mode and no data is available at the moment.\n");
-
-static PyObject *
-BufferedIOBase_read(PyObject *self, PyObject *args)
-{
- return BufferedIOBase_unsupported("read");
-}
-
-PyDoc_STRVAR(BufferedIOBase_read1_doc,
- "Read and return up to n bytes, with at most one read() call\n"
- "to the underlying raw stream. A short result does not imply\n"
- "that EOF is imminent.\n"
- "\n"
- "Returns an empty bytes object on EOF.\n");
-
-static PyObject *
-BufferedIOBase_read1(PyObject *self, PyObject *args)
-{
- return BufferedIOBase_unsupported("read1");
-}
-
-PyDoc_STRVAR(BufferedIOBase_write_doc,
- "Write the given buffer to the IO stream.\n"
- "\n"
- "Returns the number of bytes written, which is never less than\n"
- "len(b).\n"
- "\n"
- "Raises BlockingIOError if the buffer is full and the\n"
- "underlying raw stream cannot accept more data at the moment.\n");
-
-static PyObject *
-BufferedIOBase_write(PyObject *self, PyObject *args)
-{
- return BufferedIOBase_unsupported("write");
-}
-
-
-static PyMethodDef BufferedIOBase_methods[] = {
- {"read", BufferedIOBase_read, METH_VARARGS, BufferedIOBase_read_doc},
- {"read1", BufferedIOBase_read1, METH_VARARGS, BufferedIOBase_read1_doc},
- {"readinto", BufferedIOBase_readinto, METH_VARARGS, NULL},
- {"write", BufferedIOBase_write, METH_VARARGS, BufferedIOBase_write_doc},
- {NULL, NULL}
-};
-
-PyTypeObject PyBufferedIOBase_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "_io._BufferedIOBase", /*tp_name*/
- 0, /*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, /*tp_flags*/
- BufferedIOBase_doc, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- BufferedIOBase_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- &PyIOBase_Type, /* 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 */
-};
-
-
-typedef struct {
- PyObject_HEAD
-
- PyObject *raw;
- int ok; /* Initialized? */
- int readable;
- int writable;
-
- /* Absolute position inside the raw stream (-1 if unknown). */
- Py_off_t abs_pos;
-
- /* A static buffer of size `buffer_size` */
- char *buffer;
- /* Current logical position in the buffer. */
- Py_off_t pos;
- /* Position of the raw stream in the buffer. */
- Py_off_t raw_pos;
-
- /* Just after the last buffered byte in the buffer, or -1 if the buffer
- isn't ready for reading. */
- Py_off_t read_end;
-
- /* Just after the last byte actually written */
- Py_off_t write_pos;
- /* Just after the last byte waiting to be written, or -1 if the buffer
- isn't ready for writing. */
- Py_off_t write_end;
-
- PyThread_type_lock lock;
-
- Py_ssize_t buffer_size;
- Py_ssize_t buffer_mask;
-
- PyObject *dict;
- PyObject *weakreflist;
-} BufferedObject;
-
-/*
- Implementation notes:
- 
- * BufferedReader, BufferedWriter and BufferedRandom try to share most
- methods (this is helped by the members `readable` and `writable`, which
- are initialized in the respective constructors)
- * They also share a single buffer for reading and writing. This enables
- interleaved reads and writes without flushing. It also makes the logic
- a bit trickier to get right.
- * The absolute position of the raw stream is cached, if possible, in the
- `abs_pos` member. It must be updated every time an operation is done
- on the raw stream. If not sure, it can be reinitialized by calling
- _Buffered_raw_tell(), which queries the raw stream (_Buffered_raw_seek()
- also does it). To read it, use RAW_TELL().
- * Three helpers, _BufferedReader_raw_read, _BufferedWriter_raw_write and
- _BufferedWriter_flush_unlocked do a lot of useful housekeeping.
-
- NOTE: we should try to maintain block alignment of reads and writes to the
- raw stream (according to the buffer size), but for now it is only done
- in read() and friends.
- 
- XXX: method naming is a bit messy.
-*/
-
-/* These macros protect the BufferedObject against concurrent operations. */
-
-#define ENTER_BUFFERED(self) \
- Py_BEGIN_ALLOW_THREADS \
- PyThread_acquire_lock(self->lock, 1); \
- Py_END_ALLOW_THREADS
-
-#define LEAVE_BUFFERED(self) \
- PyThread_release_lock(self->lock);
-
-#define CHECK_INITIALIZED(self) \
- if (self->ok <= 0) { \
- PyErr_SetString(PyExc_ValueError, \
- "I/O operation on uninitialized object"); \
- return NULL; \
- }
-
-#define CHECK_INITIALIZED_INT(self) \
- if (self->ok <= 0) { \
- PyErr_SetString(PyExc_ValueError, \
- "I/O operation on uninitialized object"); \
- return -1; \
- }
-
-#define VALID_READ_BUFFER(self) \
- (self->readable && self->read_end != -1)
-
-#define VALID_WRITE_BUFFER(self) \
- (self->writable && self->write_end != -1)
-
-#define ADJUST_POSITION(self, _new_pos) \
- do { \
- self->pos = _new_pos; \
- if (VALID_READ_BUFFER(self) && self->read_end < self->pos) \
- self->read_end = self->pos; \
- } while(0)
-
-#define READAHEAD(self) \
- ((self->readable && VALID_READ_BUFFER(self)) \
- ? (self->read_end - self->pos) : 0)
-
-#define RAW_OFFSET(self) \
- (((VALID_READ_BUFFER(self) || VALID_WRITE_BUFFER(self)) \
- && self->raw_pos >= 0) ? self->raw_pos - self->pos : 0)
-
-#define RAW_TELL(self) \
- (self->abs_pos != -1 ? self->abs_pos : _Buffered_raw_tell(self))
-
-#define MINUS_LAST_BLOCK(self, size) \
- (self->buffer_mask ? \
- (size & ~self->buffer_mask) : \
- (self->buffer_size * (size / self->buffer_size)))
-
-
-static void
-BufferedObject_dealloc(BufferedObject *self)
-{
- if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0)
- return;
- _PyObject_GC_UNTRACK(self);
- self->ok = 0;
- if (self->weakreflist != NULL)
- PyObject_ClearWeakRefs((PyObject *)self);
- Py_CLEAR(self->raw);
- if (self->buffer) {
- PyMem_Free(self->buffer);
- self->buffer = NULL;
- }
- if (self->lock) {
- PyThread_free_lock(self->lock);
- self->lock = NULL;
- }
- Py_CLEAR(self->dict);
- Py_TYPE(self)->tp_free((PyObject *)self);
-}
-
-static int
-Buffered_traverse(BufferedObject *self, visitproc visit, void *arg)
-{
- Py_VISIT(self->raw);
- Py_VISIT(self->dict);
- return 0;
-}
-
-static int
-Buffered_clear(BufferedObject *self)
-{
- if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0)
- return -1;
- self->ok = 0;
- Py_CLEAR(self->raw);
- Py_CLEAR(self->dict);
- return 0;
-}
-
-/*
- * _BufferedIOMixin methods
- * This is not a class, just a collection of methods that will be reused
- * by BufferedReader and BufferedWriter
- */
-
-/* Flush and close */
-
-static PyObject *
-BufferedIOMixin_flush(BufferedObject *self, PyObject *args)
-{
- CHECK_INITIALIZED(self)
- return PyObject_CallMethodObjArgs(self->raw, _PyIO_str_flush, NULL);
-}
-
-static int
-BufferedIOMixin_closed(BufferedObject *self)
-{
- int closed;
- PyObject *res;
- CHECK_INITIALIZED_INT(self)
- res = PyObject_GetAttr(self->raw, _PyIO_str_closed);
- if (res == NULL)
- return -1;
- closed = PyObject_IsTrue(res);
- Py_DECREF(res);
- return closed;
-}
-
-static PyObject *
-BufferedIOMixin_closed_get(BufferedObject *self, void *context)
-{
- CHECK_INITIALIZED(self)
- return PyObject_GetAttr(self->raw, _PyIO_str_closed);
-}
-
-static PyObject *
-BufferedIOMixin_close(BufferedObject *self, PyObject *args)
-{
- PyObject *res = NULL;
- int r;
-
- CHECK_INITIALIZED(self)
- ENTER_BUFFERED(self)
-
- r = BufferedIOMixin_closed(self);
- if (r < 0)
- goto end;
- if (r > 0) {
- res = Py_None;
- Py_INCREF(res);
- goto end;
- }
- /* flush() will most probably re-take the lock, so drop it first */
- LEAVE_BUFFERED(self)
- res = PyObject_CallMethodObjArgs((PyObject *)self, _PyIO_str_flush, NULL);
- ENTER_BUFFERED(self)
- if (res == NULL) {
- /* If flush() fails, just give up */
- if (PyErr_ExceptionMatches(PyExc_IOError))
- PyErr_Clear();
- else
- goto end;
- }
- Py_XDECREF(res);
-
- res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_close, NULL);
-
-end:
- LEAVE_BUFFERED(self)
- return res;
-}
-
-/* Inquiries */
-
-static PyObject *
-BufferedIOMixin_seekable(BufferedObject *self, PyObject *args)
-{
- CHECK_INITIALIZED(self)
- return PyObject_CallMethodObjArgs(self->raw, _PyIO_str_seekable, NULL);
-}
-
-static PyObject *
-BufferedIOMixin_readable(BufferedObject *self, PyObject *args)
-{
- CHECK_INITIALIZED(self)
- return PyObject_CallMethodObjArgs(self->raw, _PyIO_str_readable, NULL);
-}
-
-static PyObject *
-BufferedIOMixin_writable(BufferedObject *self, PyObject *args)
-{
- CHECK_INITIALIZED(self)
- return PyObject_CallMethodObjArgs(self->raw, _PyIO_str_writable, NULL);
-}
-
-static PyObject *
-BufferedIOMixin_name_get(BufferedObject *self, void *context)
-{
- CHECK_INITIALIZED(self)
- return PyObject_GetAttrString(self->raw, "name");
-}
-
-static PyObject *
-BufferedIOMixin_mode_get(BufferedObject *self, void *context)
-{
- CHECK_INITIALIZED(self)
- return PyObject_GetAttrString(self->raw, "mode");
-}
-
-/* Lower-level APIs */
-
-static PyObject *
-BufferedIOMixin_fileno(BufferedObject *self, PyObject *args)
-{
- CHECK_INITIALIZED(self)
- return PyObject_CallMethodObjArgs(self->raw, _PyIO_str_fileno, NULL);
-}
-
-static PyObject *
-BufferedIOMixin_isatty(BufferedObject *self, PyObject *args)
-{
- CHECK_INITIALIZED(self)
- return PyObject_CallMethodObjArgs(self->raw, _PyIO_str_isatty, NULL);
-}
-
-
-/* Forward decls */
-static PyObject *
-_BufferedWriter_flush_unlocked(BufferedObject *, int);
-static Py_ssize_t
-_BufferedReader_fill_buffer(BufferedObject *self);
-static void
-_BufferedReader_reset_buf(BufferedObject *self);
-static void
-_BufferedWriter_reset_buf(BufferedObject *self);
-static PyObject *
-_BufferedReader_peek_unlocked(BufferedObject *self, Py_ssize_t);
-static PyObject *
-_BufferedReader_read_unlocked(BufferedObject *self, Py_ssize_t);
-
-
-/*
- * Helpers
- */
-
-/* Returns the address of the `written` member if a BlockingIOError was
- raised, NULL otherwise. The error is always re-raised. */
-static Py_ssize_t *
-_Buffered_check_blocking_error(void)
-{
- PyObject *t, *v, *tb;
- PyBlockingIOErrorObject *err;
-
- PyErr_Fetch(&t, &v, &tb);
- if (v == NULL || !PyErr_GivenExceptionMatches(v, PyExc_BlockingIOError)) {
- PyErr_Restore(t, v, tb);
- return NULL;
- }
- err = (PyBlockingIOErrorObject *) v;
- /* TODO: sanity check (err->written >= 0) */
- PyErr_Restore(t, v, tb);
- return &err->written;
-}
-
-static Py_off_t
-_Buffered_raw_tell(BufferedObject *self)
-{
- PyObject *res;
- Py_off_t n;
- res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_tell, NULL);
- if (res == NULL)
- return -1;
- n = PyNumber_AsOff_t(res, PyExc_ValueError);
- Py_DECREF(res);
- if (n < 0) {
- if (!PyErr_Occurred())
- PyErr_Format(PyExc_IOError,
- "Raw stream returned invalid position %zd", n);
- return -1;
- }
- self->abs_pos = n;
- return n;
-}
-
-static Py_off_t
-_Buffered_raw_seek(BufferedObject *self, Py_off_t target, int whence)
-{
- PyObject *res, *posobj, *whenceobj;
- Py_off_t n;
-
- posobj = PyLong_FromOff_t(target);
- if (posobj == NULL)
- return -1;
- whenceobj = PyLong_FromLong(whence);
- if (whenceobj == NULL) {
- Py_DECREF(posobj);
- return -1;
- }
- res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_seek,
- posobj, whenceobj, NULL);
- Py_DECREF(posobj);
- Py_DECREF(whenceobj);
- if (res == NULL)
- return -1;
- n = PyNumber_AsOff_t(res, PyExc_ValueError);
- Py_DECREF(res);
- if (n < 0) {
- if (!PyErr_Occurred())
- PyErr_Format(PyExc_IOError,
- "Raw stream returned invalid position %zd", n);
- return -1;
- }
- self->abs_pos = n;
- return n;
-}
-
-static int
-_Buffered_init(BufferedObject *self)
-{
- Py_ssize_t n;
- if (self->buffer_size <= 0) {
- PyErr_SetString(PyExc_ValueError,
- "buffer size must be strictly positive");
- return -1;
- }
- if (self->buffer)
- PyMem_Free(self->buffer);
- self->buffer = PyMem_Malloc(self->buffer_size);
- if (self->buffer == NULL) {
- PyErr_NoMemory();
- return -1;
- }
- self->lock = PyThread_allocate_lock();
- if (self->lock == NULL) {
- PyErr_SetString(PyExc_RuntimeError, "can't allocate read lock");
- return -1;
- }
- /* Find out whether buffer_size is a power of 2 */
- /* XXX is this optimization useful? */
- for (n = self->buffer_size - 1; n & 1; n >>= 1)
- ;
- if (n == 0)
- self->buffer_mask = self->buffer_size - 1;
- else
- self->buffer_mask = 0;
- if (_Buffered_raw_tell(self) == -1)
- PyErr_Clear();
- return 0;
-}
-
-/*
- * Shared methods and wrappers
- */
-
-static PyObject *
-Buffered_flush(BufferedObject *self, PyObject *args)
-{
- PyObject *res;
-
- CHECK_INITIALIZED(self)
- if (BufferedIOMixin_closed(self)) {
- PyErr_SetString(PyExc_ValueError, "flush of closed file");
- return NULL;
- }
-
- ENTER_BUFFERED(self)
- res = _BufferedWriter_flush_unlocked(self, 0);
- if (res != NULL && self->readable) {
- /* Rewind the raw stream so that its position corresponds to
- the current logical position. */
- Py_off_t n;
- n = _Buffered_raw_seek(self, -RAW_OFFSET(self), 1);
- if (n == -1)
- Py_CLEAR(res);
- _BufferedReader_reset_buf(self);
- }
- LEAVE_BUFFERED(self)
-
- return res;
-}
-
-static PyObject *
-Buffered_peek(BufferedObject *self, PyObject *args)
-{
- Py_ssize_t n = 0;
- PyObject *res = NULL;
-
- CHECK_INITIALIZED(self)
- if (!PyArg_ParseTuple(args, "|n:peek", &n)) {
- return NULL;
- }
-
- ENTER_BUFFERED(self)
-
- if (self->writable) {
- res = _BufferedWriter_flush_unlocked(self, 1);
- if (res == NULL)
- goto end;
- Py_CLEAR(res);
- }
- res = _BufferedReader_peek_unlocked(self, n);
-
-end:
- LEAVE_BUFFERED(self)
- return res;
-}
-
-static PyObject *
-Buffered_read(BufferedObject *self, PyObject *args)
-{
- Py_ssize_t n = -1;
- PyObject *res;
-
- CHECK_INITIALIZED(self)
- if (!PyArg_ParseTuple(args, "|n:read", &n)) {
- return NULL;
- }
- if (n < -1) {
- PyErr_SetString(PyExc_ValueError,
- "read length must be positive or -1");
- return NULL;
- }
-
- if (BufferedIOMixin_closed(self)) {
- PyErr_SetString(PyExc_ValueError, "read of closed file");
- return NULL;
- }
-
- ENTER_BUFFERED(self)
- res = _BufferedReader_read_unlocked(self, n);
- LEAVE_BUFFERED(self)
-
- return res;
-}
-
-static PyObject *
-Buffered_read1(BufferedObject *self, PyObject *args)
-{
- Py_ssize_t n, have, r;
- PyObject *res = NULL;
-
- CHECK_INITIALIZED(self)
- if (!PyArg_ParseTuple(args, "n:read1", &n)) {
- return NULL;
- }
-
- if (n < 0) {
- PyErr_SetString(PyExc_ValueError,
- "read length must be positive");
- return NULL;
- }
- if (n == 0)
- return PyBytes_FromStringAndSize(NULL, 0);
-
- ENTER_BUFFERED(self)
- 
- if (self->writable) {
- res = _BufferedWriter_flush_unlocked(self, 1);
- if (res == NULL)
- goto end;
- Py_CLEAR(res);
- }
-
- /* Return up to n bytes. If at least one byte is buffered, we
- only return buffered bytes. Otherwise, we do one raw read. */
-
- /* XXX: this mimicks the io.py implementation but is probably wrong.
- If we need to read from the raw stream, then we could actually read
- all `n` bytes asked by the caller (and possibly more, so as to fill
- our buffer for the next reads). */
-
- have = Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t);
- if (have > 0) {
- if (n > have)
- n = have;
- res = PyBytes_FromStringAndSize(self->buffer + self->pos, n);
- if (res == NULL)
- goto end;
- self->pos += n;
- goto end;
- }
-
- /* Fill the buffer from the raw stream, and copy it to the result. */
- _BufferedReader_reset_buf(self);
- r = _BufferedReader_fill_buffer(self);
- if (r == -1)
- goto end;
- if (r == -2)
- r = 0;
- if (n > r)
- n = r;
- res = PyBytes_FromStringAndSize(self->buffer, n);
- if (res == NULL)
- goto end;
- self->pos = n;
-
-end:
- LEAVE_BUFFERED(self)
- return res;
-}
-
-static PyObject *
-Buffered_readinto(BufferedObject *self, PyObject *args)
-{
- PyObject *res = NULL;
-
- CHECK_INITIALIZED(self)
- 
- /* TODO: use raw.readinto() instead! */
- if (self->writable) {
- ENTER_BUFFERED(self)
- res = _BufferedWriter_flush_unlocked(self, 0);
- LEAVE_BUFFERED(self)
- if (res == NULL)
- goto end;
- Py_DECREF(res);
- }
- res = BufferedIOBase_readinto((PyObject *)self, args);
-
-end:
- return res;
-}
-
-static PyObject *
-_Buffered_readline(BufferedObject *self, Py_ssize_t limit)
-{
- PyObject *res = NULL;
- PyObject *chunks = NULL;
- Py_ssize_t n, written = 0;
- const char *start, *s, *end;
-
- if (BufferedIOMixin_closed(self)) {
- PyErr_SetString(PyExc_ValueError, "readline of closed file");
- return NULL;
- }
-
- ENTER_BUFFERED(self)
-
- /* First, try to find a line in the buffer */
- n = Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t);
- if (limit >= 0 && n > limit)
- n = limit;
- start = self->buffer + self->pos;
- end = start + n;
- s = start;
- while (s < end) {
- if (*s++ == '\n') {
- res = PyBytes_FromStringAndSize(start, s - start);
- if (res != NULL)
- self->pos += s - start;
- goto end;
- }
- }
- if (n == limit) {
- res = PyBytes_FromStringAndSize(start, n);
- if (res != NULL)
- self->pos += n;
- goto end;
- }
-
- /* Now we try to get some more from the raw stream */
- if (self->writable) {
- res = _BufferedWriter_flush_unlocked(self, 1);
- if (res == NULL)
- goto end;
- Py_CLEAR(res);
- }
- chunks = PyList_New(0);
- if (chunks == NULL)
- goto end;
- if (n > 0) {
- res = PyBytes_FromStringAndSize(start, n);
- if (res == NULL)
- goto end;
- if (PyList_Append(chunks, res) < 0) {
- Py_CLEAR(res);
- goto end;
- }
- Py_CLEAR(res);
- written += n;
- if (limit >= 0)
- limit -= n;
- }
-
- for (;;) {
- _BufferedReader_reset_buf(self);
- n = _BufferedReader_fill_buffer(self);
- if (n == -1)
- goto end;
- if (n <= 0)
- break;
- if (limit >= 0 && n > limit)
- n = limit;
- start = self->buffer;
- end = start + n;
- s = start;
- while (s < end) {
- if (*s++ == '\n') {
- res = PyBytes_FromStringAndSize(start, s - start);
- if (res == NULL)
- goto end;
- self->pos = s - start;
- goto found;
- }
- }
- res = PyBytes_FromStringAndSize(start, n);
- if (res == NULL)
- goto end;
- if (n == limit) {
- self->pos = n;
- break;
- }
- if (PyList_Append(chunks, res) < 0) {
- Py_CLEAR(res);
- goto end;
- }
- Py_CLEAR(res);
- written += n;
- if (limit >= 0)
- limit -= n;
- }
-found:
- if (res != NULL && PyList_Append(chunks, res) < 0) {
- Py_CLEAR(res);
- goto end;
- }
- Py_CLEAR(res);
- res = _PyBytes_Join(_PyIO_empty_bytes, chunks);
-
-end:
- LEAVE_BUFFERED(self)
- Py_XDECREF(chunks);
- return res;
-}
-
-static PyObject *
-Buffered_readline(BufferedObject *self, PyObject *args)
-{
- Py_ssize_t limit = -1;
-
- CHECK_INITIALIZED(self)
-
- if (!PyArg_ParseTuple(args, "|n:readline", &limit)) {
- return NULL;
- }
- return _Buffered_readline(self, limit);
-}
-
-
-static PyObject *
-Buffered_tell(BufferedObject *self, PyObject *args)
-{
- Py_off_t pos;
-
- CHECK_INITIALIZED(self)
- pos = _Buffered_raw_tell(self);
- if (pos == -1)
- return NULL;
- pos -= RAW_OFFSET(self);
- /* TODO: sanity check (pos >= 0) */
- return PyLong_FromOff_t(pos);
-}
-
-static PyObject *
-Buffered_seek(BufferedObject *self, PyObject *args)
-{
- Py_off_t target, n;
- int whence = 0;
- PyObject *targetobj, *res = NULL;
-
- CHECK_INITIALIZED(self)
- if (!PyArg_ParseTuple(args, "O|i:seek", &targetobj, &whence)) {
- return NULL;
- }
- 
- if (whence < 0 || whence > 2) {
- PyErr_Format(PyExc_ValueError,
- "whence must be between 0 and 2, not %d", whence);
- return NULL;
- }
- target = PyNumber_AsOff_t(targetobj, PyExc_ValueError);
- if (target == -1 && PyErr_Occurred())
- return NULL;
-
- ENTER_BUFFERED(self)
-
- if (whence != 2 && self->readable) {
- Py_off_t current, avail;
- /* Check if seeking leaves us inside the current buffer,
- so as to return quickly if possible.
- Don't know how to do that when whence == 2, though. */
- current = RAW_TELL(self);
- avail = READAHEAD(self);
- if (avail > 0) {
- Py_off_t offset;
- if (whence == 0)
- offset = target - (current - RAW_OFFSET(self));
- else
- offset = target;
- if (offset >= -self->pos && offset <= avail) {
- self->pos += offset;
- res = PyLong_FromOff_t(current - avail + offset);
- goto end;
- }
- }
- }
-
- /* Fallback: invoke raw seek() method and clear buffer */
- if (self->writable) {
- res = _BufferedWriter_flush_unlocked(self, 0);
- if (res == NULL)
- goto end;
- Py_CLEAR(res);
- _BufferedWriter_reset_buf(self);
- }
-
- /* TODO: align on block boundary and read buffer if needed? */
- if (whence == 1)
- target -= RAW_OFFSET(self);
- n = _Buffered_raw_seek(self, target, whence);
- if (n == -1)
- goto end;
- self->raw_pos = -1;
- res = PyLong_FromOff_t(n);
- if (res != NULL && self->readable)
- _BufferedReader_reset_buf(self);
-
-end:
- LEAVE_BUFFERED(self)
- return res;
-}
-
-static PyObject *
-Buffered_truncate(BufferedObject *self, PyObject *args)
-{
- PyObject *pos = Py_None;
- PyObject *res = NULL;
-
- CHECK_INITIALIZED(self)
- if (!PyArg_ParseTuple(args, "|O:truncate", &pos)) {
- return NULL;
- }
-
- ENTER_BUFFERED(self)
-
- if (self->writable) {
- res = _BufferedWriter_flush_unlocked(self, 0);
- if (res == NULL)
- goto end;
- Py_CLEAR(res);
- }
- if (self->readable) {
- if (pos == Py_None) {
- /* Rewind the raw stream so that its position corresponds to
- the current logical position. */
- if (_Buffered_raw_seek(self, -RAW_OFFSET(self), 1) == -1)
- goto end;
- }
- _BufferedReader_reset_buf(self);
- }
- res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_truncate, pos, NULL);
- if (res == NULL)
- goto end;
- /* Reset cached position */
- if (_Buffered_raw_tell(self) == -1)
- PyErr_Clear();
-
-end:
- LEAVE_BUFFERED(self)
- return res;
-}
-
-static PyObject *
-Buffered_iternext(BufferedObject *self)
-{
- PyObject *line;
- PyTypeObject *tp;
-
- CHECK_INITIALIZED(self);
-
- tp = Py_TYPE(self);
- if (tp == &PyBufferedReader_Type ||
- tp == &PyBufferedRandom_Type) {
- /* Skip method call overhead for speed */
- line = _Buffered_readline(self, -1);
- }
- else {
- line = PyObject_CallMethodObjArgs((PyObject *)self,
- _PyIO_str_readline, NULL);
- if (line && !PyBytes_Check(line)) {
- PyErr_Format(PyExc_IOError,
- "readline() should have returned a bytes object, "
- "not '%.200s'", Py_TYPE(line)->tp_name);
- Py_DECREF(line);
- return NULL;
- }
- }
-
- if (line == NULL)
- return NULL;
-
- if (PyBytes_GET_SIZE(line) == 0) {
- /* Reached EOF or would have blocked */
- Py_DECREF(line);
- return NULL;
- }
-
- return line;
-}
-
-/*
- * class BufferedReader
- */
-
-PyDoc_STRVAR(BufferedReader_doc,
- "Create a new buffered reader using the given readable raw IO object.");
-
-static void _BufferedReader_reset_buf(BufferedObject *self)
-{
- self->read_end = -1;
-}
-
-static int
-BufferedReader_init(BufferedObject *self, PyObject *args, PyObject *kwds)
-{
- char *kwlist[] = {"raw", "buffer_size", NULL};
- Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
- PyObject *raw;
-
- self->ok = 0;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n:BufferedReader", kwlist,
- &raw, &buffer_size)) {
- return -1;
- }
-
- if (_PyIOBase_checkReadable(raw, Py_True) == NULL)
- return -1;
-
- Py_CLEAR(self->raw);
- Py_INCREF(raw);
- self->raw = raw;
- self->buffer_size = buffer_size;
- self->readable = 1;
- self->writable = 0;
-
- if (_Buffered_init(self) < 0)
- return -1;
- _BufferedReader_reset_buf(self);
-
- self->ok = 1;
- return 0;
-}
-
-static Py_ssize_t
-_BufferedReader_raw_read(BufferedObject *self, char *start, Py_ssize_t len)
-{
- Py_buffer buf;
- PyObject *memobj, *res;
- Py_ssize_t n;
- /* NOTE: the buffer needn't be released as its object is NULL. */
- if (PyBuffer_FillInfo(&buf, NULL, start, len, 0, PyBUF_CONTIG) == -1)
- return -1;
- memobj = PyMemoryView_FromBuffer(&buf);
- if (memobj == NULL)
- return -1;
- res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_readinto, memobj, NULL);
- Py_DECREF(memobj);
- if (res == NULL)
- return -1;
- if (res == Py_None) {
- /* Non-blocking stream would have blocked. Special return code! */
- Py_DECREF(res);
- return -2;
- }
- n = PyNumber_AsSsize_t(res, PyExc_ValueError);
- Py_DECREF(res);
- if (n < 0 || n > len) {
- PyErr_Format(PyExc_IOError,
- "raw readinto() returned invalid length %zd "
- "(should have been between 0 and %zd)", n, len);
- return -1;
- }
- if (n > 0 && self->abs_pos != -1)
- self->abs_pos += n;
- return n;
-}
-
-static Py_ssize_t
-_BufferedReader_fill_buffer(BufferedObject *self)
-{
- Py_ssize_t start, len, n;
- if (VALID_READ_BUFFER(self))
- start = Py_SAFE_DOWNCAST(self->read_end, Py_off_t, Py_ssize_t);
- else
- start = 0;
- len = self->buffer_size - start;
- n = _BufferedReader_raw_read(self, self->buffer + start, len);
- if (n <= 0)
- return n;
- self->read_end = start + n;
- self->raw_pos = start + n;
- return n;
-}
-
-static PyObject *
-_BufferedReader_read_unlocked(BufferedObject *self, Py_ssize_t n)
-{
- PyObject *data, *res = NULL;
- Py_ssize_t current_size, remaining, written;
- char *out;
-
- /* Special case for when the number of bytes to read is unspecified. */
- if (n == -1) {
- PyObject *chunks = PyList_New(0);
- if (chunks == NULL)
- return NULL;
-
- /* First copy what we have in the current buffer. */
- current_size = Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t);
- data = NULL;
- if (current_size) {
- data = PyBytes_FromStringAndSize(
- self->buffer + self->pos, current_size);
- if (data == NULL) {
- Py_DECREF(chunks);
- return NULL;
- }
- }
- _BufferedReader_reset_buf(self);
- /* We're going past the buffer's bounds, flush it */
- if (self->writable) {
- res = _BufferedWriter_flush_unlocked(self, 1);
- if (res == NULL) {
- Py_DECREF(chunks);
- return NULL;
- }
- Py_CLEAR(res);
- }
- while (1) {
- if (data) {
- if (PyList_Append(chunks, data) < 0) {
- Py_DECREF(data);
- Py_DECREF(chunks);
- return NULL;
- }
- Py_DECREF(data);
- }
-
- /* Read until EOF or until read() would block. */
- data = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_read, NULL);
- if (data == NULL) {
- Py_DECREF(chunks);
- return NULL;
- }
- if (data != Py_None && !PyBytes_Check(data)) {
- Py_DECREF(data);
- Py_DECREF(chunks);
- PyErr_SetString(PyExc_TypeError, "read() should return bytes");
- return NULL;
- }
- if (data == Py_None || PyBytes_GET_SIZE(data) == 0) {
- if (current_size == 0) {
- Py_DECREF(chunks);
- return data;
- }
- else {
- res = _PyBytes_Join(_PyIO_empty_bytes, chunks);
- Py_DECREF(data);
- Py_DECREF(chunks);
- return res;
- }
- }
- current_size += PyBytes_GET_SIZE(data);
- if (self->abs_pos != -1)
- self->abs_pos += PyBytes_GET_SIZE(data);
- }
- }
-
- /* The number of bytes to read is specified, return at most n bytes. */
- current_size = Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t);
- if (n <= current_size) {
- /* Fast path: the data to read is fully buffered. */
- res = PyBytes_FromStringAndSize(self->buffer + self->pos, n);
- if (res == NULL)
- goto error;
- self->pos += n;
- return res;
- }
-
- /* Slow path: read from the stream until enough bytes are read,
- * or until an EOF occurs or until read() would block.
- */
- res = PyBytes_FromStringAndSize(NULL, n);
- if (res == NULL)
- goto error;
- out = PyBytes_AS_STRING(res);
- remaining = n;
- written = 0;
- if (current_size > 0) {
- memcpy(out, self->buffer + self->pos, current_size);
- remaining -= current_size;
- written += current_size;
- }
- _BufferedReader_reset_buf(self);
- while (remaining > 0) {
- /* We want to read a whole block at the end into buffer.
- If we had readv() we could do this in one pass. */
- Py_ssize_t r = MINUS_LAST_BLOCK(self, remaining);
- if (r == 0)
- break;
- r = _BufferedReader_raw_read(self, out + written, r);
- if (r == -1)
- goto error;
- if (r == 0 || r == -2) {
- /* EOF occurred or read() would block. */
- if (r == 0 || written > 0) {
- if (_PyBytes_Resize(&res, written))
- goto error;
- return res;
- }
- Py_DECREF(res);
- Py_INCREF(Py_None);
- return Py_None;
- }
- remaining -= r;
- written += r;
- }
- assert(remaining <= self->buffer_size);
- self->pos = 0;
- self->raw_pos = 0;
- self->read_end = 0;
- while (self->read_end < self->buffer_size) {
- Py_ssize_t r = _BufferedReader_fill_buffer(self);
- if (r == -1)
- goto error;
- if (r == 0 || r == -2) {
- /* EOF occurred or read() would block. */
- if (r == 0 || written > 0) {
- if (_PyBytes_Resize(&res, written))
- goto error;
- return res;
- }
- Py_DECREF(res);
- Py_INCREF(Py_None);
- return Py_None;
- }
- if (remaining > r) {
- memcpy(out + written, self->buffer + self->pos, r);
- written += r;
- self->pos += r;
- remaining -= r;
- }
- else if (remaining > 0) {
- memcpy(out + written, self->buffer + self->pos, remaining);
- written += remaining;
- self->pos += remaining;
- remaining = 0;
- }
- if (remaining == 0)
- break;
- }
-
- return res;
-
-error:
- Py_XDECREF(res);
- return NULL;
-}
-
-static PyObject *
-_BufferedReader_peek_unlocked(BufferedObject *self, Py_ssize_t n)
-{
- Py_ssize_t have, r;
-
- have = Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t);
- /* Constraints:
- 1. we don't want to advance the file position.
- 2. we don't want to lose block alignment, so we can't shift the buffer
- to make some place.
- Therefore, we either return `have` bytes (if > 0), or a full buffer.
- */
- if (have > 0) {
- return PyBytes_FromStringAndSize(self->buffer + self->pos, have);
- }
-
- /* Fill the buffer from the raw stream, and copy it to the result. */
- _BufferedReader_reset_buf(self);
- r = _BufferedReader_fill_buffer(self);
- if (r == -1)
- return NULL;
- if (r == -2)
- r = 0;
- self->pos = 0;
- return PyBytes_FromStringAndSize(self->buffer, r);
-}
-
-static PyMethodDef BufferedReader_methods[] = {
- /* BufferedIOMixin methods */
- {"flush", (PyCFunction)BufferedIOMixin_flush, METH_NOARGS},
- {"close", (PyCFunction)BufferedIOMixin_close, METH_NOARGS},
- {"seekable", (PyCFunction)BufferedIOMixin_seekable, METH_NOARGS},
- {"readable", (PyCFunction)BufferedIOMixin_readable, METH_NOARGS},
- {"writable", (PyCFunction)BufferedIOMixin_writable, METH_NOARGS},
- {"fileno", (PyCFunction)BufferedIOMixin_fileno, METH_NOARGS},
- {"isatty", (PyCFunction)BufferedIOMixin_isatty, METH_NOARGS},
-
- {"read", (PyCFunction)Buffered_read, METH_VARARGS},
- {"peek", (PyCFunction)Buffered_peek, METH_VARARGS},
- {"read1", (PyCFunction)Buffered_read1, METH_VARARGS},
- {"readline", (PyCFunction)Buffered_readline, METH_VARARGS},
- {"seek", (PyCFunction)Buffered_seek, METH_VARARGS},
- {"tell", (PyCFunction)Buffered_tell, METH_NOARGS},
- {"truncate", (PyCFunction)Buffered_truncate, METH_VARARGS},
- {NULL, NULL}
-};
-
-static PyMemberDef BufferedReader_members[] = {
- {"raw", T_OBJECT, offsetof(BufferedObject, raw), 0},
- {NULL}
-};
-
-static PyGetSetDef BufferedReader_getset[] = {
- {"closed", (getter)BufferedIOMixin_closed_get, NULL, NULL},
- {"name", (getter)BufferedIOMixin_name_get, NULL, NULL},
- {"mode", (getter)BufferedIOMixin_mode_get, NULL, NULL},
- {0}
-};
-
-
-PyTypeObject PyBufferedReader_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "_io.BufferedReader", /*tp_name*/
- sizeof(BufferedObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)BufferedObject_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 | Py_TPFLAGS_BASETYPE
- | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
- BufferedReader_doc, /* tp_doc */
- (traverseproc)Buffered_traverse, /* tp_traverse */
- (inquiry)Buffered_clear, /* tp_clear */
- 0, /* tp_richcompare */
- offsetof(BufferedObject, weakreflist), /*tp_weaklistoffset*/
- 0, /* tp_iter */
- (iternextfunc)Buffered_iternext, /* tp_iternext */
- BufferedReader_methods, /* tp_methods */
- BufferedReader_members, /* tp_members */
- BufferedReader_getset, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- offsetof(BufferedObject, dict), /* tp_dictoffset */
- (initproc)BufferedReader_init, /* tp_init */
- 0, /* tp_alloc */
- PyType_GenericNew, /* tp_new */
-};
-
-
-
-static int
-complain_about_max_buffer_size(void)
-{
- if (PyErr_WarnEx(PyExc_DeprecationWarning,
- "max_buffer_size is deprecated", 1) < 0)
- return 0;
- return 1;
-}
-
-/*
- * class BufferedWriter
- */
-PyDoc_STRVAR(BufferedWriter_doc,
- "A buffer for a writeable sequential RawIO object.\n"
- "\n"
- "The constructor creates a BufferedWriter for the given writeable raw\n"
- "stream. If the buffer_size is not given, it defaults to\n"
- "DEFAULT_BUFFER_SIZE. max_buffer_size isn't used anymore.\n"
- );
-
-static void
-_BufferedWriter_reset_buf(BufferedObject *self)
-{
- self->write_pos = 0;
- self->write_end = -1;
-}
-
-static int
-BufferedWriter_init(BufferedObject *self, PyObject *args, PyObject *kwds)
-{
- /* TODO: properly deprecate max_buffer_size */
- char *kwlist[] = {"raw", "buffer_size", "max_buffer_size", NULL};
- Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
- Py_ssize_t max_buffer_size = -234;
- PyObject *raw;
-
- self->ok = 0;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|nn:BufferedReader", kwlist,
- &raw, &buffer_size, &max_buffer_size)) {
- return -1;
- }
-
- if (max_buffer_size != -234 && !complain_about_max_buffer_size())
- return -1;
-
- if (_PyIOBase_checkWritable(raw, Py_True) == NULL)
- return -1;
-
- Py_CLEAR(self->raw);
- Py_INCREF(raw);
- self->raw = raw;
- self->readable = 0;
- self->writable = 1;
-
- self->buffer_size = buffer_size;
- if (_Buffered_init(self) < 0)
- return -1;
- _BufferedWriter_reset_buf(self);
- self->pos = 0;
-
- self->ok = 1;
- return 0;
-}
-
-static Py_ssize_t
-_BufferedWriter_raw_write(BufferedObject *self, char *start, Py_ssize_t len)
-{
- Py_buffer buf;
- PyObject *memobj, *res;
- Py_ssize_t n;
- /* NOTE: the buffer needn't be released as its object is NULL. */
- if (PyBuffer_FillInfo(&buf, NULL, start, len, 1, PyBUF_CONTIG_RO) == -1)
- return -1;
- memobj = PyMemoryView_FromBuffer(&buf);
- if (memobj == NULL)
- return -1;
- res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_write, memobj, NULL);
- Py_DECREF(memobj);
- if (res == NULL)
- return -1;
- n = PyNumber_AsSsize_t(res, PyExc_ValueError);
- Py_DECREF(res);
- if (n < 0 || n > len) {
- PyErr_Format(PyExc_IOError,
- "raw write() returned invalid length %zd "
- "(should have been between 0 and %zd)", n, len);
- return -1;
- }
- if (n > 0 && self->abs_pos != -1)
- self->abs_pos += n;
- return n;
-}
-
-/* `restore_pos` is 1 if we need to restore the raw stream position at
- the end, 0 otherwise. */
-static PyObject *
-_BufferedWriter_flush_unlocked(BufferedObject *self, int restore_pos)
-{
- Py_ssize_t written = 0;
- Py_off_t n, rewind;
-
- if (!VALID_WRITE_BUFFER(self) || self->write_pos == self->write_end)
- goto end;
- /* First, rewind */
- rewind = RAW_OFFSET(self) + (self->pos - self->write_pos);
- if (rewind != 0) {
- n = _Buffered_raw_seek(self, -rewind, 1);
- if (n < 0) {
- goto error;
- }
- self->raw_pos -= rewind;
- }
- while (self->write_pos < self->write_end) {
- n = _BufferedWriter_raw_write(self,
- self->buffer + self->write_pos,
- Py_SAFE_DOWNCAST(self->write_end - self->write_pos,
- Py_off_t, Py_ssize_t));
- if (n == -1) {
- Py_ssize_t *w = _Buffered_check_blocking_error();
- if (w == NULL)
- goto error;
- self->write_pos += *w;
- self->raw_pos = self->write_pos;
- written += *w;
- *w = written;
- /* Already re-raised */
- goto error;
- }
- self->write_pos += n;
- self->raw_pos = self->write_pos;
- written += Py_SAFE_DOWNCAST(n, Py_off_t, Py_ssize_t);
- }
-
- if (restore_pos) {
- Py_off_t forward = rewind - written;
- if (forward != 0) {
- n = _Buffered_raw_seek(self, forward, 1);
- if (n < 0) {
- goto error;
- }
- self->raw_pos += forward;
- }
- }
- _BufferedWriter_reset_buf(self);
-
-end:
- Py_RETURN_NONE;
-
-error:
- return NULL;
-}
-
-static PyObject *
-BufferedWriter_write(BufferedObject *self, PyObject *args)
-{
- PyObject *res = NULL;
- Py_buffer buf;
- Py_ssize_t written, avail, remaining, n;
-
- CHECK_INITIALIZED(self)
- if (!PyArg_ParseTuple(args, "y*:write", &buf)) {
- return NULL;
- }
-
- if (BufferedIOMixin_closed(self)) {
- PyErr_SetString(PyExc_ValueError, "write to closed file");
- PyBuffer_Release(&buf);
- return NULL;
- }
-
- ENTER_BUFFERED(self)
-
- /* Fast path: the data to write can be fully buffered. */
- if (!VALID_READ_BUFFER(self) && !VALID_WRITE_BUFFER(self)) {
- self->pos = 0;
- self->raw_pos = 0;
- }
- avail = Py_SAFE_DOWNCAST(self->buffer_size - self->pos, Py_off_t, Py_ssize_t);
- if (buf.len <= avail) {
- memcpy(self->buffer + self->pos, buf.buf, buf.len);
- if (!VALID_WRITE_BUFFER(self)) {
- self->write_pos = self->pos;
- }
- ADJUST_POSITION(self, self->pos + buf.len);
- if (self->pos > self->write_end)
- self->write_end = self->pos;
- written = buf.len;
- goto end;
- }
-
- /* First write the current buffer */
- res = _BufferedWriter_flush_unlocked(self, 0);
- if (res == NULL) {
- Py_ssize_t *w = _Buffered_check_blocking_error();
- if (w == NULL)
- goto error;
- if (self->readable)
- _BufferedReader_reset_buf(self);
- /* Make some place by shifting the buffer. */
- assert(VALID_WRITE_BUFFER(self));
- memmove(self->buffer, self->buffer + self->write_pos,
- Py_SAFE_DOWNCAST(self->write_end - self->write_pos,
- Py_off_t, Py_ssize_t));
- self->write_end -= self->write_pos;
- self->raw_pos -= self->write_pos;
- self->pos -= self->write_pos;
- self->write_pos = 0;
- avail = Py_SAFE_DOWNCAST(self->buffer_size - self->write_end,
- Py_off_t, Py_ssize_t);
- if (buf.len <= avail) {
- /* Everything can be buffered */
- PyErr_Clear();
- memcpy(self->buffer + self->write_end, buf.buf, buf.len);
- self->write_end += buf.len;
- written = buf.len;
- goto end;
- }
- /* Buffer as much as possible. */
- memcpy(self->buffer + self->write_end, buf.buf, avail);
- self->write_end += avail;
- /* Already re-raised */
- *w = avail;
- goto error;
- }
- Py_CLEAR(res);
-
- /* Then write buf itself. At this point the buffer has been emptied. */
- remaining = buf.len;
- written = 0;
- while (remaining > self->buffer_size) {
- n = _BufferedWriter_raw_write(
- self, (char *) buf.buf + written, buf.len - written);
- if (n == -1) {
- Py_ssize_t *w = _Buffered_check_blocking_error();
- if (w == NULL)
- goto error;
- written += *w;
- remaining -= *w;
- if (remaining > self->buffer_size) {
- /* Can't buffer everything, still buffer as much as possible */
- memcpy(self->buffer,
- (char *) buf.buf + written, self->buffer_size);
- self->raw_pos = 0;
- ADJUST_POSITION(self, self->buffer_size);
- self->write_end = self->buffer_size;
- *w = written + self->buffer_size;
- /* Already re-raised */
- goto error;
- }
- PyErr_Clear();
- break;
- }
- written += n;
- remaining -= n;
- }
- if (self->readable)
- _BufferedReader_reset_buf(self);
- if (remaining > 0) {
- memcpy(self->buffer, (char *) buf.buf + written, remaining);
- written += remaining;
- }
- self->write_pos = 0;
- /* TODO: sanity check (remaining >= 0) */
- self->write_end = remaining;
- ADJUST_POSITION(self, remaining);
- self->raw_pos = 0;
-
-end:
- res = PyLong_FromSsize_t(written);
-
-error:
- LEAVE_BUFFERED(self)
- PyBuffer_Release(&buf);
- return res;
-}
-
-static PyMethodDef BufferedWriter_methods[] = {
- /* BufferedIOMixin methods */
- {"close", (PyCFunction)BufferedIOMixin_close, METH_NOARGS},
- {"seekable", (PyCFunction)BufferedIOMixin_seekable, METH_NOARGS},
- {"readable", (PyCFunction)BufferedIOMixin_readable, METH_NOARGS},
- {"writable", (PyCFunction)BufferedIOMixin_writable, METH_NOARGS},
- {"fileno", (PyCFunction)BufferedIOMixin_fileno, METH_NOARGS},
- {"isatty", (PyCFunction)BufferedIOMixin_isatty, METH_NOARGS},
-
- {"write", (PyCFunction)BufferedWriter_write, METH_VARARGS},
- {"truncate", (PyCFunction)Buffered_truncate, METH_VARARGS},
- {"flush", (PyCFunction)Buffered_flush, METH_NOARGS},
- {"seek", (PyCFunction)Buffered_seek, METH_VARARGS},
- {"tell", (PyCFunction)Buffered_tell, METH_NOARGS},
- {NULL, NULL}
-};
-
-static PyMemberDef BufferedWriter_members[] = {
- {"raw", T_OBJECT, offsetof(BufferedObject, raw), 0},
- {NULL}
-};
-
-static PyGetSetDef BufferedWriter_getset[] = {
- {"closed", (getter)BufferedIOMixin_closed_get, NULL, NULL},
- {"name", (getter)BufferedIOMixin_name_get, NULL, NULL},
- {"mode", (getter)BufferedIOMixin_mode_get, NULL, NULL},
- {0}
-};
-
-
-PyTypeObject PyBufferedWriter_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "_io.BufferedWriter", /*tp_name*/
- sizeof(BufferedObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)BufferedObject_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 | Py_TPFLAGS_BASETYPE
- | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
- BufferedWriter_doc, /* tp_doc */
- (traverseproc)Buffered_traverse, /* tp_traverse */
- (inquiry)Buffered_clear, /* tp_clear */
- 0, /* tp_richcompare */
- offsetof(BufferedObject, weakreflist), /*tp_weaklistoffset*/
- 0, /* tp_iter */
- 0, /* tp_iternext */
- BufferedWriter_methods, /* tp_methods */
- BufferedWriter_members, /* tp_members */
- BufferedWriter_getset, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- offsetof(BufferedObject, dict), /* tp_dictoffset */
- (initproc)BufferedWriter_init, /* tp_init */
- 0, /* tp_alloc */
- PyType_GenericNew, /* tp_new */
-};
-
-
-
-/*
- * BufferedRWPair
- */
-
-PyDoc_STRVAR(BufferedRWPair_doc,
- "A buffered reader and writer object together.\n"
- "\n"
- "A buffered reader object and buffered writer object put together to\n"
- "form a sequential IO object that can read and write. This is typically\n"
- "used with a socket or two-way pipe.\n"
- "\n"
- "reader and writer are RawIOBase objects that are readable and\n"
- "writeable respectively. If the buffer_size is omitted it defaults to\n"
- "DEFAULT_BUFFER_SIZE.\n"
- );
-
-/* XXX The usefulness of this (compared to having two separate IO objects) is
- * questionable.
- */
-
-typedef struct {
- PyObject_HEAD
- BufferedObject *reader;
- BufferedObject *writer;
- PyObject *dict;
- PyObject *weakreflist;
-} BufferedRWPairObject;
-
-static int
-BufferedRWPair_init(BufferedRWPairObject *self, PyObject *args,
- PyObject *kwds)
-{
- PyObject *reader, *writer;
- Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
- Py_ssize_t max_buffer_size = -234;
-
- if (!PyArg_ParseTuple(args, "OO|nn:BufferedRWPair", &reader, &writer,
- &buffer_size, &max_buffer_size)) {
- return -1;
- }
-
- if (max_buffer_size != -234 && !complain_about_max_buffer_size())
- return -1;
-
- if (_PyIOBase_checkReadable(reader, Py_True) == NULL)
- return -1;
- if (_PyIOBase_checkWritable(writer, Py_True) == NULL)
- return -1;
-
- args = Py_BuildValue("(n)", buffer_size);
- if (args == NULL) {
- Py_CLEAR(self->reader);
- return -1;
- }
- self->reader = (BufferedObject *)PyType_GenericNew(
- &PyBufferedReader_Type, args, NULL);
- Py_DECREF(args);
- if (self->reader == NULL)
- return -1;
-
- args = Py_BuildValue("(n)", buffer_size);
- if (args == NULL) {
- Py_CLEAR(self->reader);
- return -1;
- }
- self->writer = (BufferedObject *)PyType_GenericNew(
- &PyBufferedWriter_Type, args, NULL);
- Py_DECREF(args);
- if (self->writer == NULL) {
- Py_CLEAR(self->reader);
- return -1;
- }
- return 0;
-}
-
-static int
-BufferedRWPair_traverse(BufferedRWPairObject *self, visitproc visit, void *arg)
-{
- Py_VISIT(self->dict);
- return 0;
-}
-
-static int
-BufferedRWPair_clear(BufferedRWPairObject *self)
-{
- Py_CLEAR(self->reader);
- Py_CLEAR(self->writer);
- Py_CLEAR(self->dict);
- return 0;
-}
-
-static void
-BufferedRWPair_dealloc(BufferedRWPairObject *self)
-{
- _PyObject_GC_UNTRACK(self);
- Py_CLEAR(self->reader);
- Py_CLEAR(self->writer);
- Py_CLEAR(self->dict);
- Py_TYPE(self)->tp_free((PyObject *) self);
-}
-
-static PyObject *
-_forward_call(BufferedObject *self, const char *name, PyObject *args)
-{
- PyObject *func = PyObject_GetAttrString((PyObject *)self, name);
- PyObject *ret;
-
- if (func == NULL) {
- PyErr_SetString(PyExc_AttributeError, name);
- return NULL;
- }
-
- ret = PyObject_CallObject(func, args);
- Py_DECREF(func);
- return ret;
-}
-
-static PyObject *
-BufferedRWPair_read(BufferedRWPairObject *self, PyObject *args)
-{
- return _forward_call(self->reader, "read", args);
-}
-
-static PyObject *
-BufferedRWPair_peek(BufferedRWPairObject *self, PyObject *args)
-{
- return _forward_call(self->reader, "peek", args);
-}
-
-static PyObject *
-BufferedRWPair_read1(BufferedRWPairObject *self, PyObject *args)
-{
- return _forward_call(self->reader, "read1", args);
-}
-
-static PyObject *
-BufferedRWPair_write(BufferedRWPairObject *self, PyObject *args)
-{
- return _forward_call(self->writer, "write", args);
-}
-
-static PyObject *
-BufferedRWPair_flush(BufferedRWPairObject *self, PyObject *args)
-{
- return _forward_call(self->writer, "flush", args);
-}
-
-static PyObject *
-BufferedRWPair_readable(BufferedRWPairObject *self, PyObject *args)
-{
- return _forward_call(self->reader, "readable", args);
-}
-
-static PyObject *
-BufferedRWPair_writable(BufferedRWPairObject *self, PyObject *args)
-{
- return _forward_call(self->writer, "writable", args);
-}
-
-static PyObject *
-BufferedRWPair_close(BufferedRWPairObject *self, PyObject *args)
-{
- PyObject *ret = _forward_call(self->writer, "close", args);
- if (ret == NULL)
- return NULL;
- Py_DECREF(ret);
-
- return _forward_call(self->reader, "close", args);
-}
-
-static PyObject *
-BufferedRWPair_isatty(BufferedRWPairObject *self, PyObject *args)
-{
- PyObject *ret = _forward_call(self->writer, "isatty", args);
-
- if (ret != Py_False) {
- /* either True or exception */
- return ret;
- }
- Py_DECREF(ret);
-
- return _forward_call(self->reader, "isatty", args);
-}
-
-
-static PyMethodDef BufferedRWPair_methods[] = {
- {"read", (PyCFunction)BufferedRWPair_read, METH_VARARGS},
- {"peek", (PyCFunction)BufferedRWPair_peek, METH_VARARGS},
- {"read1", (PyCFunction)BufferedRWPair_read1, METH_VARARGS},
- {"readinto", (PyCFunction)Buffered_readinto, METH_VARARGS},
-
- {"write", (PyCFunction)BufferedRWPair_write, METH_VARARGS},
- {"flush", (PyCFunction)BufferedRWPair_flush, METH_NOARGS},
-
- {"readable", (PyCFunction)BufferedRWPair_readable, METH_NOARGS},
- {"writable", (PyCFunction)BufferedRWPair_writable, METH_NOARGS},
-
- {"close", (PyCFunction)BufferedRWPair_close, METH_NOARGS},
- {"isatty", (PyCFunction)BufferedRWPair_isatty, METH_NOARGS},
-
- {NULL, NULL}
-};
-
-PyTypeObject PyBufferedRWPair_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "_io.BufferedRWPair", /*tp_name*/
- sizeof(BufferedRWPairObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)BufferedRWPair_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 | Py_TPFLAGS_BASETYPE
- | Py_TPFLAGS_HAVE_GC, /* tp_flags */
- BufferedRWPair_doc, /* tp_doc */
- (traverseproc)BufferedRWPair_traverse, /* tp_traverse */
- (inquiry)BufferedRWPair_clear, /* tp_clear */
- 0, /* tp_richcompare */
- offsetof(BufferedRWPairObject, weakreflist), /*tp_weaklistoffset*/
- 0, /* tp_iter */
- 0, /* tp_iternext */
- BufferedRWPair_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- offsetof(BufferedRWPairObject, dict), /* tp_dictoffset */
- (initproc)BufferedRWPair_init, /* tp_init */
- 0, /* tp_alloc */
- PyType_GenericNew, /* tp_new */
-};
-
-
-
-/*
- * BufferedRandom
- */
-
-PyDoc_STRVAR(BufferedRandom_doc,
- "A buffered interface to random access streams.\n"
- "\n"
- "The constructor creates a reader and writer for a seekable stream,\n"
- "raw, given in the first argument. If the buffer_size is omitted it\n"
- "defaults to DEFAULT_BUFFER_SIZE. max_buffer_size isn't used anymore.\n"
- );
-
-static int
-BufferedRandom_init(BufferedObject *self, PyObject *args, PyObject *kwds)
-{
- char *kwlist[] = {"raw", "buffer_size", "max_buffer_size", NULL};
- Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
- Py_ssize_t max_buffer_size = -234;
- PyObject *raw;
-
- self->ok = 0;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|nn:BufferedReader", kwlist,
- &raw, &buffer_size, &max_buffer_size)) {
- return -1;
- }
-
- if (max_buffer_size != -234 && !complain_about_max_buffer_size())
- return -1;
-
- if (_PyIOBase_checkSeekable(raw, Py_True) == NULL)
- return -1;
- if (_PyIOBase_checkReadable(raw, Py_True) == NULL)
- return -1;
- if (_PyIOBase_checkWritable(raw, Py_True) == NULL)
- return -1;
-
- Py_CLEAR(self->raw);
- Py_INCREF(raw);
- self->raw = raw;
- self->buffer_size = buffer_size;
- self->readable = 1;
- self->writable = 1;
-
- if (_Buffered_init(self) < 0)
- return -1;
- _BufferedReader_reset_buf(self);
- _BufferedWriter_reset_buf(self);
- self->pos = 0;
-
- self->ok = 1;
- return 0;
-}
-
-static PyMethodDef BufferedRandom_methods[] = {
- /* BufferedIOMixin methods */
- {"close", (PyCFunction)BufferedIOMixin_close, METH_NOARGS},
- {"seekable", (PyCFunction)BufferedIOMixin_seekable, METH_NOARGS},
- {"readable", (PyCFunction)BufferedIOMixin_readable, METH_NOARGS},
- {"writable", (PyCFunction)BufferedIOMixin_writable, METH_NOARGS},
- {"fileno", (PyCFunction)BufferedIOMixin_fileno, METH_NOARGS},
- {"isatty", (PyCFunction)BufferedIOMixin_isatty, METH_NOARGS},
-
- {"flush", (PyCFunction)Buffered_flush, METH_NOARGS},
-
- {"seek", (PyCFunction)Buffered_seek, METH_VARARGS},
- {"tell", (PyCFunction)Buffered_tell, METH_NOARGS},
- {"truncate", (PyCFunction)Buffered_truncate, METH_VARARGS},
- {"read", (PyCFunction)Buffered_read, METH_VARARGS},
- {"read1", (PyCFunction)Buffered_read1, METH_VARARGS},
- {"readinto", (PyCFunction)Buffered_readinto, METH_VARARGS},
- {"readline", (PyCFunction)Buffered_readline, METH_VARARGS},
- {"peek", (PyCFunction)Buffered_peek, METH_VARARGS},
- {"write", (PyCFunction)BufferedWriter_write, METH_VARARGS},
- {NULL, NULL}
-};
-
-static PyMemberDef BufferedRandom_members[] = {
- {"raw", T_OBJECT, offsetof(BufferedObject, raw), 0},
- {NULL}
-};
-
-static PyGetSetDef BufferedRandom_getset[] = {
- {"closed", (getter)BufferedIOMixin_closed_get, NULL, NULL},
- {"name", (getter)BufferedIOMixin_name_get, NULL, NULL},
- {"mode", (getter)BufferedIOMixin_mode_get, NULL, NULL},
- {0}
-};
-
-
-PyTypeObject PyBufferedRandom_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "_io.BufferedRandom", /*tp_name*/
- sizeof(BufferedObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)BufferedObject_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 | Py_TPFLAGS_BASETYPE
- | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
- BufferedRandom_doc, /* tp_doc */
- (traverseproc)Buffered_traverse, /* tp_traverse */
- (inquiry)Buffered_clear, /* tp_clear */
- 0, /* tp_richcompare */
- offsetof(BufferedObject, weakreflist), /*tp_weaklistoffset*/
- 0, /* tp_iter */
- (iternextfunc)Buffered_iternext, /* tp_iternext */
- BufferedRandom_methods, /* tp_methods */
- BufferedRandom_members, /* tp_members */
- BufferedRandom_getset, /* tp_getset */
- 0, /* tp_base */
- 0, /*tp_dict*/
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- offsetof(BufferedObject, dict), /*tp_dictoffset*/
- (initproc)BufferedRandom_init, /* tp_init */
- 0, /* tp_alloc */
- PyType_GenericNew, /* tp_new */
-};
-
Deleted: python/branches/py3k-short-float-repr/Modules/_bytesio.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/_bytesio.c	Sun Apr 5 01:04:14 2009
+++ (empty file)
@@ -1,757 +0,0 @@
-#include "Python.h"
-#include "structmember.h" /* for offsetof() */
-#include "_iomodule.h"
-
-typedef struct {
- PyObject_HEAD
- char *buf;
- Py_ssize_t pos;
- Py_ssize_t string_size;
- size_t buf_size;
- PyObject *dict;
- PyObject *weakreflist;
-} BytesIOObject;
-
-#define CHECK_CLOSED(self) \
- if ((self)->buf == NULL) { \
- PyErr_SetString(PyExc_ValueError, \
- "I/O operation on closed file."); \
- return NULL; \
- }
-
-/* Internal routine to get a line from the buffer of a BytesIO
- object. Returns the length between the current position to the
- next newline character. */
-static Py_ssize_t
-get_line(BytesIOObject *self, char **output)
-{
- char *n;
- const char *str_end;
- Py_ssize_t len;
-
- assert(self->buf != NULL);
-
- /* Move to the end of the line, up to the end of the string, s. */
- str_end = self->buf + self->string_size;
- for (n = self->buf + self->pos;
- n < str_end && *n != '\n';
- n++);
-
- /* Skip the newline character */
- if (n < str_end)
- n++;
-
- /* Get the length from the current position to the end of the line. */
- len = n - (self->buf + self->pos);
- *output = self->buf + self->pos;
-
- assert(len >= 0);
- assert(self->pos < PY_SSIZE_T_MAX - len);
- self->pos += len;
-
- return len;
-}
-
-/* Internal routine for changing the size of the buffer of BytesIO objects.
- The caller should ensure that the 'size' argument is non-negative. Returns
- 0 on success, -1 otherwise. */
-static int
-resize_buffer(BytesIOObject *self, size_t size)
-{
- /* Here, unsigned types are used to avoid dealing with signed integer
- overflow, which is undefined in C. */
- size_t alloc = self->buf_size;
- char *new_buf = NULL;
-
- assert(self->buf != NULL);
-
- /* For simplicity, stay in the range of the signed type. Anyway, Python
- doesn't allow strings to be longer than this. */
- if (size > PY_SSIZE_T_MAX)
- goto overflow;
-
- if (size < alloc / 2) {
- /* Major downsize; resize down to exact size. */
- alloc = size + 1;
- }
- else if (size < alloc) {
- /* Within allocated size; quick exit */
- return 0;
- }
- else if (size <= alloc * 1.125) {
- /* Moderate upsize; overallocate similar to list_resize() */
- alloc = size + (size >> 3) + (size < 9 ? 3 : 6);
- }
- else {
- /* Major upsize; resize up to exact size */
- alloc = size + 1;
- }
-
- if (alloc > ((size_t)-1) / sizeof(char))
- goto overflow;
- new_buf = (char *)PyMem_Realloc(self->buf, alloc * sizeof(char));
- if (new_buf == NULL) {
- PyErr_NoMemory();
- return -1;
- }
- self->buf_size = alloc;
- self->buf = new_buf;
-
- return 0;
-
- overflow:
- PyErr_SetString(PyExc_OverflowError,
- "new buffer size too large");
- return -1;
-}
-
-/* Internal routine for writing a string of bytes to the buffer of a BytesIO
- object. Returns the number of bytes wrote, or -1 on error. */
-static Py_ssize_t
-write_bytes(BytesIOObject *self, const char *bytes, Py_ssize_t len)
-{
- assert(self->buf != NULL);
- assert(self->pos >= 0);
- assert(len >= 0);
-
- if ((size_t)self->pos + len > self->buf_size) {
- if (resize_buffer(self, (size_t)self->pos + len) < 0)
- return -1;
- }
-
- if (self->pos > self->string_size) {
- /* In case of overseek, pad with null bytes the buffer region between
- the end of stream and the current position.
-
- 0 lo string_size hi
- | |<---used--->|<----------available----------->|
- | | <--to pad-->|<---to write---> |
- 0 buf position
- */
- memset(self->buf + self->string_size, '0円',
- (self->pos - self->string_size) * sizeof(char));
- }
-
- /* Copy the data to the internal buffer, overwriting some of the existing
- data if self->pos < self->string_size. */
- memcpy(self->buf + self->pos, bytes, len);
- self->pos += len;
-
- /* Set the new length of the internal string if it has changed. */
- if (self->string_size < self->pos) {
- self->string_size = self->pos;
- }
-
- return len;
-}
-
-static PyObject *
-bytesio_get_closed(BytesIOObject *self)
-{
- if (self->buf == NULL) {
- Py_RETURN_TRUE;
- }
- else {
- Py_RETURN_FALSE;
- }
-}
-
-/* Generic getter for the writable, readable and seekable properties */
-static PyObject *
-return_true(BytesIOObject *self)
-{
- Py_RETURN_TRUE;
-}
-
-PyDoc_STRVAR(flush_doc,
-"flush() -> None. Does nothing.");
-
-static PyObject *
-bytesio_flush(BytesIOObject *self)
-{
- Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(getval_doc,
-"getvalue() -> bytes.\n"
-"\n"
-"Retrieve the entire contents of the BytesIO object.");
-
-static PyObject *
-bytesio_getvalue(BytesIOObject *self)
-{
- CHECK_CLOSED(self);
- return PyBytes_FromStringAndSize(self->buf, self->string_size);
-}
-
-PyDoc_STRVAR(isatty_doc,
-"isatty() -> False.\n"
-"\n"
-"Always returns False since BytesIO objects are not connected\n"
-"to a tty-like device.");
-
-static PyObject *
-bytesio_isatty(BytesIOObject *self)
-{
- CHECK_CLOSED(self);
- Py_RETURN_FALSE;
-}
-
-PyDoc_STRVAR(tell_doc,
-"tell() -> current file position, an integer\n");
-
-static PyObject *
-bytesio_tell(BytesIOObject *self)
-{
- CHECK_CLOSED(self);
- return PyLong_FromSsize_t(self->pos);
-}
-
-PyDoc_STRVAR(read_doc,
-"read([size]) -> read at most size bytes, returned as a string.\n"
-"\n"
-"If the size argument is negative, read until EOF is reached.\n"
-"Return an empty string at EOF.");
-
-static PyObject *
-bytesio_read(BytesIOObject *self, PyObject *args)
-{
- Py_ssize_t size, n;
- char *output;
- PyObject *arg = Py_None;
-
- CHECK_CLOSED(self);
-
- if (!PyArg_ParseTuple(args, "|O:read", &arg))
- return NULL;
-
- if (PyLong_Check(arg)) {
- size = PyLong_AsSsize_t(arg);
- if (size == -1 && PyErr_Occurred())
- return NULL;
- }
- else if (arg == Py_None) {
- /* Read until EOF is reached, by default. */
- size = -1;
- }
- else {
- PyErr_Format(PyExc_TypeError, "integer argument expected, got '%s'",
- Py_TYPE(arg)->tp_name);
- return NULL;
- }
-
- /* adjust invalid sizes */
- n = self->string_size - self->pos;
- if (size < 0 || size > n) {
- size = n;
- if (size < 0)
- size = 0;
- }
-
- assert(self->buf != NULL);
- output = self->buf + self->pos;
- self->pos += size;
-
- return PyBytes_FromStringAndSize(output, size);
-}
-
-
-PyDoc_STRVAR(read1_doc,
-"read1(size) -> read at most size bytes, returned as a string.\n"
-"\n"
-"If the size argument is negative or omitted, read until EOF is reached.\n"
-"Return an empty string at EOF.");
-
-static PyObject *
-bytesio_read1(BytesIOObject *self, PyObject *n)
-{
- PyObject *arg, *res;
-
- arg = PyTuple_Pack(1, n);
- if (arg == NULL)
- return NULL;
- res = bytesio_read(self, arg);
- Py_DECREF(arg);
- return res;
-}
-
-PyDoc_STRVAR(readline_doc,
-"readline([size]) -> next line from the file, as a string.\n"
-"\n"
-"Retain newline. A non-negative size argument limits the maximum\n"
-"number of bytes to return (an incomplete line may be returned then).\n"
-"Return an empty string at EOF.\n");
-
-static PyObject *
-bytesio_readline(BytesIOObject *self, PyObject *args)
-{
- Py_ssize_t size, n;
- char *output;
- PyObject *arg = Py_None;
-
- CHECK_CLOSED(self);
-
- if (!PyArg_ParseTuple(args, "|O:readline", &arg))
- return NULL;
-
- if (PyLong_Check(arg)) {
- size = PyLong_AsSsize_t(arg);
- if (size == -1 && PyErr_Occurred())
- return NULL;
- }
- else if (arg == Py_None) {
- /* No size limit, by default. */
- size = -1;
- }
- else {
- PyErr_Format(PyExc_TypeError, "integer argument expected, got '%s'",
- Py_TYPE(arg)->tp_name);
- return NULL;
- }
-
- n = get_line(self, &output);
-
- if (size >= 0 && size < n) {
- size = n - size;
- n -= size;
- self->pos -= size;
- }
-
- return PyBytes_FromStringAndSize(output, n);
-}
-
-PyDoc_STRVAR(readlines_doc,
-"readlines([size]) -> list of strings, each a line from the file.\n"
-"\n"
-"Call readline() repeatedly and return a list of the lines so read.\n"
-"The optional size argument, if given, is an approximate bound on the\n"
-"total number of bytes in the lines returned.\n");
-
-static PyObject *
-bytesio_readlines(BytesIOObject *self, PyObject *args)
-{
- Py_ssize_t maxsize, size, n;
- PyObject *result, *line;
- char *output;
- PyObject *arg = Py_None;
-
- CHECK_CLOSED(self);
-
- if (!PyArg_ParseTuple(args, "|O:readlines", &arg))
- return NULL;
-
- if (PyLong_Check(arg)) {
- maxsize = PyLong_AsSsize_t(arg);
- if (maxsize == -1 && PyErr_Occurred())
- return NULL;
- }
- else if (arg == Py_None) {
- /* No size limit, by default. */
- maxsize = -1;
- }
- else {
- PyErr_Format(PyExc_TypeError, "integer argument expected, got '%s'",
- Py_TYPE(arg)->tp_name);
- return NULL;
- }
-
- size = 0;
- result = PyList_New(0);
- if (!result)
- return NULL;
-
- while ((n = get_line(self, &output)) != 0) {
- line = PyBytes_FromStringAndSize(output, n);
- if (!line)
- goto on_error;
- if (PyList_Append(result, line) == -1) {
- Py_DECREF(line);
- goto on_error;
- }
- Py_DECREF(line);
- size += n;
- if (maxsize > 0 && size >= maxsize)
- break;
- }
- return result;
-
- on_error:
- Py_DECREF(result);
- return NULL;
-}
-
-PyDoc_STRVAR(readinto_doc,
-"readinto(bytearray) -> int. Read up to len(b) bytes into b.\n"
-"\n"
-"Returns number of bytes read (0 for EOF), or None if the object\n"
-"is set not to block as has no data to read.");
-
-static PyObject *
-bytesio_readinto(BytesIOObject *self, PyObject *buffer)
-{
- void *raw_buffer;
- Py_ssize_t len;
-
- CHECK_CLOSED(self);
-
- if (PyObject_AsWriteBuffer(buffer, &raw_buffer, &len) == -1)
- return NULL;
-
- if (self->pos + len > self->string_size)
- len = self->string_size - self->pos;
-
- memcpy(raw_buffer, self->buf + self->pos, len);
- assert(self->pos + len < PY_SSIZE_T_MAX);
- assert(len >= 0);
- self->pos += len;
-
- return PyLong_FromSsize_t(len);
-}
-
-PyDoc_STRVAR(truncate_doc,
-"truncate([size]) -> int. Truncate the file to at most size bytes.\n"
-"\n"
-"Size defaults to the current file position, as returned by tell().\n"
-"Returns the new size. Imply an absolute seek to the position size.");
-
-static PyObject *
-bytesio_truncate(BytesIOObject *self, PyObject *args)
-{
- Py_ssize_t size;
- PyObject *arg = Py_None;
-
- CHECK_CLOSED(self);
-
- if (!PyArg_ParseTuple(args, "|O:truncate", &arg))
- return NULL;
-
- if (PyLong_Check(arg)) {
- size = PyLong_AsSsize_t(arg);
- if (size == -1 && PyErr_Occurred())
- return NULL;
- }
- else if (arg == Py_None) {
- /* Truncate to current position if no argument is passed. */
- size = self->pos;
- }
- else {
- PyErr_Format(PyExc_TypeError, "integer argument expected, got '%s'",
- Py_TYPE(arg)->tp_name);
- return NULL;
- }
-
- if (size < 0) {
- PyErr_Format(PyExc_ValueError,
- "negative size value %zd", size);
- return NULL;
- }
-
- if (size < self->string_size) {
- self->string_size = size;
- if (resize_buffer(self, size) < 0)
- return NULL;
- }
- self->pos = size;
-
- return PyLong_FromSsize_t(size);
-}
-
-static PyObject *
-bytesio_iternext(BytesIOObject *self)
-{
- char *next;
- Py_ssize_t n;
-
- CHECK_CLOSED(self);
-
- n = get_line(self, &next);
-
- if (!next || n == 0)
- return NULL;
-
- return PyBytes_FromStringAndSize(next, n);
-}
-
-PyDoc_STRVAR(seek_doc,
-"seek(pos, whence=0) -> int. Change stream position.\n"
-"\n"
-"Seek to byte offset pos relative to position indicated by whence:\n"
-" 0 Start of stream (the default). pos should be >= 0;\n"
-" 1 Current position - pos may be negative;\n"
-" 2 End of stream - pos usually negative.\n"
-"Returns the new absolute position.");
-
-static PyObject *
-bytesio_seek(BytesIOObject *self, PyObject *args)
-{
- Py_ssize_t pos;
- int mode = 0;
-
- CHECK_CLOSED(self);
-
- if (!PyArg_ParseTuple(args, "n|i:seek", &pos, &mode))
- return NULL;
-
- if (pos < 0 && mode == 0) {
- PyErr_Format(PyExc_ValueError,
- "negative seek value %zd", pos);
- return NULL;
- }
-
- /* mode 0: offset relative to beginning of the string.
- mode 1: offset relative to current position.
- mode 2: offset relative the end of the string. */
- if (mode == 1) {
- if (pos > PY_SSIZE_T_MAX - self->pos) {
- PyErr_SetString(PyExc_OverflowError,
- "new position too large");
- return NULL;
- }
- pos += self->pos;
- }
- else if (mode == 2) {
- if (pos > PY_SSIZE_T_MAX - self->string_size) {
- PyErr_SetString(PyExc_OverflowError,
- "new position too large");
- return NULL;
- }
- pos += self->string_size;
- }
- else if (mode != 0) {
- PyErr_Format(PyExc_ValueError,
- "invalid whence (%i, should be 0, 1 or 2)", mode);
- return NULL;
- }
-
- if (pos < 0)
- pos = 0;
- self->pos = pos;
-
- return PyLong_FromSsize_t(self->pos);
-}
-
-PyDoc_STRVAR(write_doc,
-"write(bytes) -> int. Write bytes to file.\n"
-"\n"
-"Return the number of bytes written.");
-
-static PyObject *
-bytesio_write(BytesIOObject *self, PyObject *obj)
-{
- Py_ssize_t n = 0;
- Py_buffer buf;
- PyObject *result = NULL;
-
- CHECK_CLOSED(self);
-
- if (PyObject_GetBuffer(obj, &buf, PyBUF_CONTIG_RO) < 0)
- return NULL;
-
- if (buf.len != 0)
- n = write_bytes(self, buf.buf, buf.len);
- if (n >= 0)
- result = PyLong_FromSsize_t(n);
-
- PyBuffer_Release(&buf);
- return result;
-}
-
-PyDoc_STRVAR(writelines_doc,
-"writelines(sequence_of_strings) -> None. Write strings to the file.\n"
-"\n"
-"Note that newlines are not added. The sequence can be any iterable\n"
-"object producing strings. This is equivalent to calling write() for\n"
-"each string.");
-
-static PyObject *
-bytesio_writelines(BytesIOObject *self, PyObject *v)
-{
- PyObject *it, *item;
- PyObject *ret;
-
- CHECK_CLOSED(self);
-
- it = PyObject_GetIter(v);
- if (it == NULL)
- return NULL;
-
- while ((item = PyIter_Next(it)) != NULL) {
- ret = bytesio_write(self, item);
- Py_DECREF(item);
- if (ret == NULL) {
- Py_DECREF(it);
- return NULL;
- }
- Py_DECREF(ret);
- }
- Py_DECREF(it);
-
- /* See if PyIter_Next failed */
- if (PyErr_Occurred())
- return NULL;
-
- Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(close_doc,
-"close() -> None. Disable all I/O operations.");
-
-static PyObject *
-bytesio_close(BytesIOObject *self)
-{
- if (self->buf != NULL) {
- PyMem_Free(self->buf);
- self->buf = NULL;
- }
- Py_RETURN_NONE;
-}
-
-static void
-bytesio_dealloc(BytesIOObject *self)
-{
- if (self->buf != NULL) {
- PyMem_Free(self->buf);
- self->buf = NULL;
- }
- Py_TYPE(self)->tp_clear((PyObject *)self);
- Py_TYPE(self)->tp_free(self);
-}
-
-static PyObject *
-bytesio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- BytesIOObject *self;
-
- assert(type != NULL && type->tp_alloc != NULL);
- self = (BytesIOObject *)type->tp_alloc(type, 0);
- if (self == NULL)
- return NULL;
-
- self->string_size = 0;
- self->pos = 0;
- self->buf_size = 0;
- self->buf = (char *)PyMem_Malloc(0);
- if (self->buf == NULL) {
- Py_DECREF(self);
- return PyErr_NoMemory();
- }
-
- return (PyObject *)self;
-}
-
-static int
-bytesio_init(BytesIOObject *self, PyObject *args, PyObject *kwds)
-{
- PyObject *initvalue = NULL;
-
- if (!PyArg_ParseTuple(args, "|O:BytesIO", &initvalue))
- return -1;
-
- /* In case, __init__ is called multiple times. */
- self->string_size = 0;
- self->pos = 0;
-
- if (initvalue && initvalue != Py_None) {
- PyObject *res;
- res = bytesio_write(self, initvalue);
- if (res == NULL)
- return -1;
- Py_DECREF(res);
- self->pos = 0;
- }
-
- return 0;
-}
-
-static int
-bytesio_traverse(BytesIOObject *self, visitproc visit, void *arg)
-{
- Py_VISIT(self->dict);
- Py_VISIT(self->weakreflist);
- return 0;
-}
-
-static int
-bytesio_clear(BytesIOObject *self)
-{
- Py_CLEAR(self->dict);
- if (self->weakreflist != NULL)
- PyObject_ClearWeakRefs((PyObject *)self);
- return 0;
-}
-
-
-static PyGetSetDef bytesio_getsetlist[] = {
- {"closed", (getter)bytesio_get_closed, NULL,
- "True if the file is closed."},
- {0}, /* sentinel */
-};
-
-static struct PyMethodDef bytesio_methods[] = {
- {"readable", (PyCFunction)return_true, METH_NOARGS, NULL},
- {"seekable", (PyCFunction)return_true, METH_NOARGS, NULL},
- {"writable", (PyCFunction)return_true, METH_NOARGS, NULL},
- {"close", (PyCFunction)bytesio_close, METH_NOARGS, close_doc},
- {"flush", (PyCFunction)bytesio_flush, METH_NOARGS, flush_doc},
- {"isatty", (PyCFunction)bytesio_isatty, METH_NOARGS, isatty_doc},
- {"tell", (PyCFunction)bytesio_tell, METH_NOARGS, tell_doc},
- {"write", (PyCFunction)bytesio_write, METH_O, write_doc},
- {"writelines", (PyCFunction)bytesio_writelines, METH_O, writelines_doc},
- {"read1", (PyCFunction)bytesio_read1, METH_O, read1_doc},
- {"readinto", (PyCFunction)bytesio_readinto, METH_O, readinto_doc},
- {"readline", (PyCFunction)bytesio_readline, METH_VARARGS, readline_doc},
- {"readlines", (PyCFunction)bytesio_readlines, METH_VARARGS, readlines_doc},
- {"read", (PyCFunction)bytesio_read, METH_VARARGS, read_doc},
- {"getvalue", (PyCFunction)bytesio_getvalue, METH_VARARGS, getval_doc},
- {"seek", (PyCFunction)bytesio_seek, METH_VARARGS, seek_doc},
- {"truncate", (PyCFunction)bytesio_truncate, METH_VARARGS, truncate_doc},
- {NULL, NULL} /* sentinel */
-};
-
-PyDoc_STRVAR(bytesio_doc,
-"BytesIO([buffer]) -> object\n"
-"\n"
-"Create a buffered I/O implementation using an in-memory bytes\n"
-"buffer, ready for reading and writing.");
-
-PyTypeObject PyBytesIO_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "_io.BytesIO", /*tp_name*/
- sizeof(BytesIOObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)bytesio_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_reserved*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash*/
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
- Py_TPFLAGS_HAVE_GC, /*tp_flags*/
- bytesio_doc, /*tp_doc*/
- (traverseproc)bytesio_traverse, /*tp_traverse*/
- (inquiry)bytesio_clear, /*tp_clear*/
- 0, /*tp_richcompare*/
- offsetof(BytesIOObject, weakreflist), /*tp_weaklistoffset*/
- PyObject_SelfIter, /*tp_iter*/
- (iternextfunc)bytesio_iternext, /*tp_iternext*/
- bytesio_methods, /*tp_methods*/
- 0, /*tp_members*/
- bytesio_getsetlist, /*tp_getset*/
- 0, /*tp_base*/
- 0, /*tp_dict*/
- 0, /*tp_descr_get*/
- 0, /*tp_descr_set*/
- offsetof(BytesIOObject, dict), /*tp_dictoffset*/
- (initproc)bytesio_init, /*tp_init*/
- 0, /*tp_alloc*/
- bytesio_new, /*tp_new*/
-};
Modified: python/branches/py3k-short-float-repr/Modules/_cursesmodule.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/_cursesmodule.c	(original)
+++ python/branches/py3k-short-float-repr/Modules/_cursesmodule.c	Sun Apr 5 01:04:14 2009
@@ -890,7 +890,7 @@
 PyErr_SetString(PyCursesError, "no input");
 return NULL;
 } else if (rtn<=255)
- return Py_BuildValue("c", rtn);
+ return Py_BuildValue("C", rtn);
 else
 #if defined(__NetBSD__)
 return PyUnicode_FromString(unctrl(rtn));
Deleted: python/branches/py3k-short-float-repr/Modules/_fileio.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/_fileio.c	Sun Apr 5 01:04:14 2009
+++ (empty file)
@@ -1,1034 +0,0 @@
-/* Author: Daniel Stutzbach */
-
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stddef.h> /* For offsetof */
-#include "_iomodule.h"
-
-/*
- * Known likely problems:
- *
- * - Files larger then 2**32-1
- * - Files with unicode filenames
- * - Passing numbers greater than 2**32-1 when an integer is expected
- * - Making it work on Windows and other oddball platforms
- *
- * To Do:
- *
- * - autoconfify header file inclusion
- */
-
-#ifdef MS_WINDOWS
-/* can simulate truncate with Win32 API functions; see file_truncate */
-#define HAVE_FTRUNCATE
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#endif
-
-#if BUFSIZ < (8*1024)
-#define SMALLCHUNK (8*1024)
-#elif (BUFSIZ >= (2 << 25))
-#error "unreasonable BUFSIZ > 64MB defined"
-#else
-#define SMALLCHUNK BUFSIZ
-#endif
-
-#if SIZEOF_INT < 4
-#define BIGCHUNK (512 * 32)
-#else
-#define BIGCHUNK (512 * 1024)
-#endif
-
-typedef struct {
-	PyObject_HEAD
-	int fd;
-	unsigned readable : 1;
-	unsigned writable : 1;
-	int seekable : 2; /* -1 means unknown */
-	int closefd : 1;
-	PyObject *weakreflist;
-	PyObject *dict;
-} PyFileIOObject;
-
-PyTypeObject PyFileIO_Type;
-
-#define PyFileIO_Check(op) (PyObject_TypeCheck((op), &PyFileIO_Type))
-
-int
-_PyFileIO_closed(PyObject *self)
-{
-	return ((PyFileIOObject *)self)->fd < 0;
-}
-
-static PyObject *
-portable_lseek(int fd, PyObject *posobj, int whence);
-
-static PyObject *portable_lseek(int fd, PyObject *posobj, int whence);
-
-/* Returns 0 on success, -1 with exception set on failure. */
-static int
-internal_close(PyFileIOObject *self)
-{
-	int err = 0;
-	int save_errno = 0;
-	if (self->fd >= 0) {
-		int fd = self->fd;
-		self->fd = -1;
-		/* fd is accessible and someone else may have closed it */
-		if (_PyVerify_fd(fd)) {
-			Py_BEGIN_ALLOW_THREADS
-			err = close(fd);
-			if (err < 0)
-				save_errno = errno;
-			Py_END_ALLOW_THREADS
-		} else {
-			save_errno = errno;
-			err = -1;
-		}
-	}
-	if (err < 0) {
-		errno = save_errno;
-		PyErr_SetFromErrno(PyExc_IOError);
-		return -1;
-	}
-	return 0;
-}
-
-static PyObject *
-fileio_close(PyFileIOObject *self)
-{
-	if (!self->closefd) {
-		self->fd = -1;
-		Py_RETURN_NONE;
-	}
-	errno = internal_close(self);
-	if (errno < 0)
-		return NULL;
-
-	return PyObject_CallMethod((PyObject*)&PyRawIOBase_Type,
-				 "close", "O", self);
-}
-
-static PyObject *
-fileio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
-	PyFileIOObject *self;
-
-	assert(type != NULL && type->tp_alloc != NULL);
-
-	self = (PyFileIOObject *) type->tp_alloc(type, 0);
-	if (self != NULL) {
-		self->fd = -1;
-		self->readable = 0;
-		self->writable = 0;
-		self->seekable = -1;
-		self->closefd = 1;
-		self->weakreflist = NULL;
-	}
-
-	return (PyObject *) self;
-}
-
-/* On Unix, open will succeed for directories.
- In Python, there should be no file objects referring to
- directories, so we need a check. */
-
-static int
-dircheck(PyFileIOObject* self, const char *name)
-{
-#if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR)
-	struct stat buf;
-	if (self->fd < 0)
-		return 0;
-	if (fstat(self->fd, &buf) == 0 && S_ISDIR(buf.st_mode)) {
-		char *msg = strerror(EISDIR);
-		PyObject *exc;
-		if (internal_close(self))
-			return -1;
-
-		exc = PyObject_CallFunction(PyExc_IOError, "(iss)",
-					 EISDIR, msg, name);
-		PyErr_SetObject(PyExc_IOError, exc);
-		Py_XDECREF(exc);
-		return -1;
-	}
-#endif
-	return 0;
-}
-
-static int
-check_fd(int fd)
-{
-#if defined(HAVE_FSTAT)
-	struct stat buf;
-	if (!_PyVerify_fd(fd) || (fstat(fd, &buf) < 0 && errno == EBADF)) {
-		PyObject *exc;
-		char *msg = strerror(EBADF);
-		exc = PyObject_CallFunction(PyExc_OSError, "(is)",
-					 EBADF, msg);
-		PyErr_SetObject(PyExc_OSError, exc);
-		Py_XDECREF(exc);
-		return -1;
-	}
-#endif
-	return 0;
-}
-
-
-static int
-fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
-{
-	PyFileIOObject *self = (PyFileIOObject *) oself;
-	static char *kwlist[] = {"file", "mode", "closefd", NULL};
-	const char *name = NULL;
-	PyObject *nameobj, *stringobj = NULL;
-	char *mode = "r";
-	char *s;
-#ifdef MS_WINDOWS
-	Py_UNICODE *widename = NULL;
-#endif
-	int ret = 0;
-	int rwa = 0, plus = 0, append = 0;
-	int flags = 0;
-	int fd = -1;
-	int closefd = 1;
-
-	assert(PyFileIO_Check(oself));
-	if (self->fd >= 0) {
-		/* Have to close the existing file first. */
-		if (internal_close(self) < 0)
-			return -1;
-	}
-
-	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|si:fileio",
-					 kwlist, &nameobj, &mode, &closefd))
-		return -1;
-
-	if (PyFloat_Check(nameobj)) {
-		PyErr_SetString(PyExc_TypeError,
-				"integer argument expected, got float");
-		return -1;
-	}
-
-	fd = PyLong_AsLong(nameobj);
-	if (fd < 0) {
-		if (!PyErr_Occurred()) {
-			PyErr_SetString(PyExc_ValueError,
-					"Negative filedescriptor");
-			return -1;
-		}
-		PyErr_Clear();
-	}
-
-#ifdef Py_WIN_WIDE_FILENAMES
-	if (GetVersion() < 0x80000000) {
-		/* On NT, so wide API available */
-		if (PyUnicode_Check(nameobj))
-			widename = PyUnicode_AS_UNICODE(nameobj);
-	}
-	if (widename == NULL)
-#endif
-	if (fd < 0)
-	{
-		if (PyBytes_Check(nameobj) || PyByteArray_Check(nameobj)) {
-			Py_ssize_t namelen;
-			if (PyObject_AsCharBuffer(nameobj, &name, &namelen) < 0)
-				return -1;
-		}
-		else {
-			PyObject *u = PyUnicode_FromObject(nameobj);
-
-			if (u == NULL)
-				return -1;
-
-			stringobj = PyUnicode_AsEncodedString(
-				u, Py_FileSystemDefaultEncoding, NULL);
-			Py_DECREF(u);
-			if (stringobj == NULL)
-				return -1;
-			if (!PyBytes_Check(stringobj)) {
-				PyErr_SetString(PyExc_TypeError,
-						"encoder failed to return bytes");
-				goto error;
-			}
-			name = PyBytes_AS_STRING(stringobj);
-		}
-	}
-
-	s = mode;
-	while (*s) {
-		switch (*s++) {
-		case 'r':
-			if (rwa) {
-			bad_mode:
-				PyErr_SetString(PyExc_ValueError,
-						"Must have exactly one of read/write/append mode");
-				goto error;
-			}
-			rwa = 1;
-			self->readable = 1;
-			break;
-		case 'w':
-			if (rwa)
-				goto bad_mode;
-			rwa = 1;
-			self->writable = 1;
-			flags |= O_CREAT | O_TRUNC;
-			break;
-		case 'a':
-			if (rwa)
-				goto bad_mode;
-			rwa = 1;
-			self->writable = 1;
-			flags |= O_CREAT;
-			append = 1;
-			break;
-		case 'b':
-			break;
-		case '+':
-			if (plus)
-				goto bad_mode;
-			self->readable = self->writable = 1;
-			plus = 1;
-			break;
-		default:
-			PyErr_Format(PyExc_ValueError,
-				 "invalid mode: %.200s", mode);
-			goto error;
-		}
-	}
-
-	if (!rwa)
-		goto bad_mode;
-
-	if (self->readable && self->writable)
-		flags |= O_RDWR;
-	else if (self->readable)
-		flags |= O_RDONLY;
-	else
-		flags |= O_WRONLY;
-
-#ifdef O_BINARY
-	flags |= O_BINARY;
-#endif
-
-#ifdef O_APPEND
-	if (append)
-		flags |= O_APPEND;
-#endif
-
-	if (fd >= 0) {
-		if (check_fd(fd))
-			goto error;
-		self->fd = fd;
-		self->closefd = closefd;
-	}
-	else {
-		self->closefd = 1;
-		if (!closefd) {
-			PyErr_SetString(PyExc_ValueError,
- "Cannot use closefd=False with file name");
-			goto error;
-		}
-
-		Py_BEGIN_ALLOW_THREADS
-		errno = 0;
-#ifdef MS_WINDOWS
-		if (widename != NULL)
-			self->fd = _wopen(widename, flags, 0666);
-		else
-#endif
-			self->fd = open(name, flags, 0666);
-		Py_END_ALLOW_THREADS
-		if (self->fd < 0) {
-#ifdef MS_WINDOWS
-			if (widename != NULL)
-				PyErr_SetFromErrnoWithUnicodeFilename(PyExc_IOError, widename);
-			else
-#endif
-				PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
-			goto error;
-		}
-		if(dircheck(self, name) < 0)
-			goto error;
-	}
-
-	if (PyObject_SetAttrString((PyObject *)self, "name", nameobj) < 0)
-		goto error;
-
-	if (append) {
-		/* For consistent behaviour, we explicitly seek to the
-		 end of file (otherwise, it might be done only on the
-		 first write()). */
-		PyObject *pos = portable_lseek(self->fd, NULL, 2);
-		if (pos == NULL)
-			goto error;
-		Py_DECREF(pos);
-	}
-
-	goto done;
-
- error:
-	ret = -1;
-
- done:
-	Py_CLEAR(stringobj);
-	return ret;
-}
-
-static int
-fileio_traverse(PyFileIOObject *self, visitproc visit, void *arg)
-{
-	Py_VISIT(self->dict);
-	return 0;
-}
-
-static int
-fileio_clear(PyFileIOObject *self)
-{
-	Py_CLEAR(self->dict);
-	return 0;
-}
-
-static void
-fileio_dealloc(PyFileIOObject *self)
-{
-	if (_PyIOBase_finalize((PyObject *) self) < 0)
-		return;
-	_PyObject_GC_UNTRACK(self);
-	if (self->weakreflist != NULL)
-		PyObject_ClearWeakRefs((PyObject *) self);
-	Py_CLEAR(self->dict);
-	Py_TYPE(self)->tp_free((PyObject *)self);
-}
-
-static PyObject *
-err_closed(void)
-{
-	PyErr_SetString(PyExc_ValueError, "I/O operation on closed file");
-	return NULL;
-}
-
-static PyObject *
-err_mode(char *action)
-{
-	PyErr_Format(PyExc_ValueError, "File not open for %s", action);
-	return NULL;
-}
-
-static PyObject *
-fileio_fileno(PyFileIOObject *self)
-{
-	if (self->fd < 0)
-		return err_closed();
-	return PyLong_FromLong((long) self->fd);
-}
-
-static PyObject *
-fileio_readable(PyFileIOObject *self)
-{
-	if (self->fd < 0)
-		return err_closed();
-	return PyBool_FromLong((long) self->readable);
-}
-
-static PyObject *
-fileio_writable(PyFileIOObject *self)
-{
-	if (self->fd < 0)
-		return err_closed();
-	return PyBool_FromLong((long) self->writable);
-}
-
-static PyObject *
-fileio_seekable(PyFileIOObject *self)
-{
-	if (self->fd < 0)
-		return err_closed();
-	if (self->seekable < 0) {
-		PyObject *pos = portable_lseek(self->fd, NULL, SEEK_CUR);
-		if (pos == NULL) {
-			PyErr_Clear();
-			self->seekable = 0;
-		} else {
-			Py_DECREF(pos);
-			self->seekable = 1;
-		}
-	}
-	return PyBool_FromLong((long) self->seekable);
-}
-
-static PyObject *
-fileio_readinto(PyFileIOObject *self, PyObject *args)
-{
-	Py_buffer pbuf;
-	Py_ssize_t n;
-
-	if (self->fd < 0)
-		return err_closed();
-	if (!self->readable)
-		return err_mode("reading");
-
-	if (!PyArg_ParseTuple(args, "w*", &pbuf))
-		return NULL;
-
-	if (_PyVerify_fd(self->fd)) {
-		Py_BEGIN_ALLOW_THREADS
-		errno = 0;
-		n = read(self->fd, pbuf.buf, pbuf.len);
-		Py_END_ALLOW_THREADS
-	} else
-		n = -1;
-	PyBuffer_Release(&pbuf);
-	if (n < 0) {
-		if (errno == EAGAIN)
-			Py_RETURN_NONE;
-		PyErr_SetFromErrno(PyExc_IOError);
-		return NULL;
-	}
-
-	return PyLong_FromSsize_t(n);
-}
-
-static size_t
-new_buffersize(PyFileIOObject *self, size_t currentsize)
-{
-#ifdef HAVE_FSTAT
-	off_t pos, end;
-	struct stat st;
-	if (fstat(self->fd, &st) == 0) {
-		end = st.st_size;
-		pos = lseek(self->fd, 0L, SEEK_CUR);
-		/* Files claiming a size smaller than SMALLCHUNK may
-		 actually be streaming pseudo-files. In this case, we
-		 apply the more aggressive algorithm below.
-		*/
-		if (end >= SMALLCHUNK && end >= pos && pos >= 0) {
-			/* Add 1 so if the file were to grow we'd notice. */
-			return currentsize + end - pos + 1;
-		}
-	}
-#endif
-	if (currentsize > SMALLCHUNK) {
-		/* Keep doubling until we reach BIGCHUNK;
-		 then keep adding BIGCHUNK. */
-		if (currentsize <= BIGCHUNK)
-			return currentsize + currentsize;
-		else
-			return currentsize + BIGCHUNK;
-	}
-	return currentsize + SMALLCHUNK;
-}
-
-static PyObject *
-fileio_readall(PyFileIOObject *self)
-{
-	PyObject *result;
-	Py_ssize_t total = 0;
-	int n;
-
-	if (!_PyVerify_fd(self->fd))
-		return PyErr_SetFromErrno(PyExc_IOError);
-
-	result = PyBytes_FromStringAndSize(NULL, SMALLCHUNK);
-	if (result == NULL)
-		return NULL;
-
-	while (1) {
-		size_t newsize = new_buffersize(self, total);
-		if (newsize > PY_SSIZE_T_MAX || newsize <= 0) {
-			PyErr_SetString(PyExc_OverflowError,
-				"unbounded read returned more bytes "
-				"than a Python string can hold ");
-			Py_DECREF(result);
-			return NULL;
-		}
-
-		if (PyBytes_GET_SIZE(result) < newsize) {
-			if (_PyBytes_Resize(&result, newsize) < 0) {
-				if (total == 0) {
-					Py_DECREF(result);
-					return NULL;
-				}
-				PyErr_Clear();
-				break;
-			}
-		}
-		Py_BEGIN_ALLOW_THREADS
-		errno = 0;
-		n = read(self->fd,
-			 PyBytes_AS_STRING(result) + total,
-			 newsize - total);
-		Py_END_ALLOW_THREADS
-		if (n == 0)
-			break;
-		if (n < 0) {
-			if (total > 0)
-				break;
-			if (errno == EAGAIN) {
-				Py_DECREF(result);
-				Py_RETURN_NONE;
-			}
-			Py_DECREF(result);
-			PyErr_SetFromErrno(PyExc_IOError);
-			return NULL;
-		}
-		total += n;
-	}
-
-	if (PyBytes_GET_SIZE(result) > total) {
-		if (_PyBytes_Resize(&result, total) < 0) {
-			/* This should never happen, but just in case */
-			Py_DECREF(result);
-			return NULL;
-		}
-	}
-	return result;
-}
-
-static PyObject *
-fileio_read(PyFileIOObject *self, PyObject *args)
-{
-	char *ptr;
-	Py_ssize_t n;
-	Py_ssize_t size = -1;
-	PyObject *bytes;
-
-	if (self->fd < 0)
-		return err_closed();
-	if (!self->readable)
-		return err_mode("reading");
-
-	if (!PyArg_ParseTuple(args, "|n", &size))
-		return NULL;
-
- if (size < 0) {
-		return fileio_readall(self);
-	}
-
-	bytes = PyBytes_FromStringAndSize(NULL, size);
-	if (bytes == NULL)
-		return NULL;
-	ptr = PyBytes_AS_STRING(bytes);
-
-	if (_PyVerify_fd(self->fd)) {
-		Py_BEGIN_ALLOW_THREADS
-		errno = 0;
-		n = read(self->fd, ptr, size);
-		Py_END_ALLOW_THREADS
-	} else
-		n = -1;
-
-	if (n < 0) {
-		Py_DECREF(bytes);
-		if (errno == EAGAIN)
-			Py_RETURN_NONE;
-		PyErr_SetFromErrno(PyExc_IOError);
-		return NULL;
-	}
-
-	if (n != size) {
-		if (_PyBytes_Resize(&bytes, n) < 0) {
-			Py_DECREF(bytes);
-			return NULL;
-		}
-	}
-
-	return (PyObject *) bytes;
-}
-
-static PyObject *
-fileio_write(PyFileIOObject *self, PyObject *args)
-{
-	Py_buffer pbuf;
-	Py_ssize_t n;
-
-	if (self->fd < 0)
-		return err_closed();
-	if (!self->writable)
-		return err_mode("writing");
-
-	if (!PyArg_ParseTuple(args, "s*", &pbuf))
-		return NULL;
-
-	if (_PyVerify_fd(self->fd)) {
-		Py_BEGIN_ALLOW_THREADS
-		errno = 0;
-		n = write(self->fd, pbuf.buf, pbuf.len);
-		Py_END_ALLOW_THREADS
-	} else
-		n = -1;
-
-	PyBuffer_Release(&pbuf);
-
-	if (n < 0) {
-		if (errno == EAGAIN)
-			Py_RETURN_NONE;
-		PyErr_SetFromErrno(PyExc_IOError);
-		return NULL;
-	}
-
-	return PyLong_FromSsize_t(n);
-}
-
-/* XXX Windows support below is likely incomplete */
-
-/* Cribbed from posix_lseek() */
-static PyObject *
-portable_lseek(int fd, PyObject *posobj, int whence)
-{
-	Py_off_t pos, res;
-
-#ifdef SEEK_SET
-	/* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */
-	switch (whence) {
-#if SEEK_SET != 0
-	case 0: whence = SEEK_SET; break;
-#endif
-#if SEEK_CUR != 1
-	case 1: whence = SEEK_CUR; break;
-#endif
-#if SEEK_END != 2
-	case 2: whence = SEEK_END; break;
-#endif
-	}
-#endif /* SEEK_SET */
-
-	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 = PyLong_AsLongLong(posobj);
-#else
-		pos = PyLong_AsLong(posobj);
-#endif
-		if (PyErr_Occurred())
-			return NULL;
-	}
-
-	if (_PyVerify_fd(fd)) {
-		Py_BEGIN_ALLOW_THREADS
-#if defined(MS_WIN64) || defined(MS_WINDOWS)
-		res = _lseeki64(fd, pos, whence);
-#else
-		res = lseek(fd, pos, whence);
-#endif
-		Py_END_ALLOW_THREADS
-	} else
-		res = -1;
-	if (res < 0)
-		return PyErr_SetFromErrno(PyExc_IOError);
-
-#if defined(HAVE_LARGEFILE_SUPPORT)
-	return PyLong_FromLongLong(res);
-#else
-	return PyLong_FromLong(res);
-#endif
-}
-
-static PyObject *
-fileio_seek(PyFileIOObject *self, PyObject *args)
-{
-	PyObject *posobj;
-	int whence = 0;
-
-	if (self->fd < 0)
-		return err_closed();
-
-	if (!PyArg_ParseTuple(args, "O|i", &posobj, &whence))
-		return NULL;
-
-	return portable_lseek(self->fd, posobj, whence);
-}
-
-static PyObject *
-fileio_tell(PyFileIOObject *self, PyObject *args)
-{
-	if (self->fd < 0)
-		return err_closed();
-
-	return portable_lseek(self->fd, NULL, 1);
-}
-
-#ifdef HAVE_FTRUNCATE
-static PyObject *
-fileio_truncate(PyFileIOObject *self, PyObject *args)
-{
-	PyObject *posobj = NULL;
-	Py_off_t pos;
-	int ret;
-	int fd;
-
-	fd = self->fd;
-	if (fd < 0)
-		return err_closed();
-	if (!self->writable)
-		return err_mode("writing");
-
-	if (!PyArg_ParseTuple(args, "|O", &posobj))
-		return NULL;
-
-	if (posobj == Py_None || posobj == NULL) {
-		/* Get the current position. */
- posobj = portable_lseek(fd, NULL, 1);
- if (posobj == NULL)
-			return NULL;
- }
- else {
-		/* Move to the position to be truncated. */
- posobj = portable_lseek(fd, posobj, 0);
- }
-	if (posobj == NULL)
-		return NULL;
-
-#if defined(HAVE_LARGEFILE_SUPPORT)
-	pos = PyLong_AsLongLong(posobj);
-#else
-	pos = PyLong_AsLong(posobj);
-#endif
-	if (pos == -1 && PyErr_Occurred())
-		return NULL;
-
-#ifdef MS_WINDOWS
-	/* MS _chsize doesn't work if newsize doesn't fit in 32 bits,
-	 so don't even try using it. */
-	{
-		HANDLE hFile;
-
-		/* Truncate. Note that this may grow the file! */
-		Py_BEGIN_ALLOW_THREADS
-		errno = 0;
-		hFile = (HANDLE)_get_osfhandle(fd);
-		ret = hFile == (HANDLE)-1;
-		if (ret == 0) {
-			ret = SetEndOfFile(hFile) == 0;
-			if (ret)
-				errno = EACCES;
-		}
-		Py_END_ALLOW_THREADS
-	}
-#else
-	Py_BEGIN_ALLOW_THREADS
-	errno = 0;
-	ret = ftruncate(fd, pos);
-	Py_END_ALLOW_THREADS
-#endif /* !MS_WINDOWS */
-
-	if (ret != 0) {
-		PyErr_SetFromErrno(PyExc_IOError);
-		return NULL;
-	}
-
-	return posobj;
-}
-#endif
-
-static char *
-mode_string(PyFileIOObject *self)
-{
-	if (self->readable) {
-		if (self->writable)
-			return "rb+";
-		else
-			return "rb";
-	}
-	else
-		return "wb";
-}
-
-static PyObject *
-fileio_repr(PyFileIOObject *self)
-{
- if (self->fd < 0)
-		return PyUnicode_FromFormat("io.FileIO(-1)");
-
-	return PyUnicode_FromFormat("io.FileIO(%d, '%s')",
-				 self->fd, mode_string(self));
-}
-
-static PyObject *
-fileio_isatty(PyFileIOObject *self)
-{
-	long res;
-
-	if (self->fd < 0)
-		return err_closed();
-	Py_BEGIN_ALLOW_THREADS
-	res = isatty(self->fd);
-	Py_END_ALLOW_THREADS
-	return PyBool_FromLong(res);
-}
-
-
-PyDoc_STRVAR(fileio_doc,
-"file(name: str[, mode: str]) -> file IO object\n"
-"\n"
-"Open a file. The mode can be 'r', 'w' or 'a' for reading (default),\n"
-"writing or appending.	The file will be created if it doesn't exist\n"
-"when opened for writing or appending; it will be truncated when\n"
-"opened for writing. Add a '+' to the mode to allow simultaneous\n"
-"reading and writing.");
-
-PyDoc_STRVAR(read_doc,
-"read(size: int) -> bytes. read at most size bytes, returned as bytes.\n"
-"\n"
-"Only makes one system call, so less data may be returned than requested\n"
-"In non-blocking mode, returns None if no data is available.\n"
-"On end-of-file, returns ''.");
-
-PyDoc_STRVAR(readall_doc,
-"readall() -> bytes. read all data from the file, returned as bytes.\n"
-"\n"
-"In non-blocking mode, returns as much as is immediately available,\n"
-"or None if no data is available. On end-of-file, returns ''.");
-
-PyDoc_STRVAR(write_doc,
-"write(b: bytes) -> int. Write bytes b to file, return number written.\n"
-"\n"
-"Only makes one system call, so not all of the data may be written.\n"
-"The number of bytes actually written is returned.");
-
-PyDoc_STRVAR(fileno_doc,
-"fileno() -> int. \"file descriptor\".\n"
-"\n"
-"This is needed for lower-level file interfaces, such the fcntl module.");
-
-PyDoc_STRVAR(seek_doc,
-"seek(offset: int[, whence: int]) -> None. Move to new file position.\n"
-"\n"
-"Argument offset is a byte count. Optional argument whence defaults to\n"
-"0 (offset from start of file, offset should be >= 0); other values are 1\n"
-"(move relative to current position, positive or negative), and 2 (move\n"
-"relative to end of file, usually negative, although many platforms allow\n"
-"seeking beyond the end of a file)."
-"\n"
-"Note that not all file objects are seekable.");
-
-#ifdef HAVE_FTRUNCATE
-PyDoc_STRVAR(truncate_doc,
-"truncate([size: int]) -> None.	 Truncate the file to at most size bytes.\n"
-"\n"
-"Size defaults to the current file position, as returned by tell()."
-"The current file position is changed to the value of size.");
-#endif
-
-PyDoc_STRVAR(tell_doc,
-"tell() -> int.	 Current file position");
-
-PyDoc_STRVAR(readinto_doc,
-"readinto() -> Same as RawIOBase.readinto().");
-
-PyDoc_STRVAR(close_doc,
-"close() -> None. Close the file.\n"
-"\n"
-"A closed file cannot be used for further I/O operations. close() may be\n"
-"called more than once without error. Changes the fileno to -1.");
-
-PyDoc_STRVAR(isatty_doc,
-"isatty() -> bool. True if the file is connected to a tty device.");
-
-PyDoc_STRVAR(seekable_doc,
-"seekable() -> bool. True if file supports random-access.");
-
-PyDoc_STRVAR(readable_doc,
-"readable() -> bool. True if file was opened in a read mode.");
-
-PyDoc_STRVAR(writable_doc,
-"writable() -> bool. True if file was opened in a write mode.");
-
-static PyMethodDef fileio_methods[] = {
-	{"read", (PyCFunction)fileio_read,	 METH_VARARGS, read_doc},
-	{"readall", (PyCFunction)fileio_readall, METH_NOARGS, readall_doc},
-	{"readinto", (PyCFunction)fileio_readinto, METH_VARARGS, readinto_doc},
-	{"write", (PyCFunction)fileio_write,	 METH_VARARGS, write_doc},
-	{"seek", (PyCFunction)fileio_seek,	 METH_VARARGS, seek_doc},
-	{"tell", (PyCFunction)fileio_tell,	 METH_VARARGS, tell_doc},
-#ifdef HAVE_FTRUNCATE
-	{"truncate", (PyCFunction)fileio_truncate, METH_VARARGS, truncate_doc},
-#endif
-	{"close", (PyCFunction)fileio_close,	 METH_NOARGS,	 close_doc},
-	{"seekable", (PyCFunction)fileio_seekable, METH_NOARGS,	 seekable_doc},
-	{"readable", (PyCFunction)fileio_readable, METH_NOARGS,	 readable_doc},
-	{"writable", (PyCFunction)fileio_writable, METH_NOARGS,	 writable_doc},
-	{"fileno", (PyCFunction)fileio_fileno, METH_NOARGS,	 fileno_doc},
-	{"isatty", (PyCFunction)fileio_isatty, METH_NOARGS,	 isatty_doc},
-	{NULL,	 NULL}	 /* sentinel */
-};
-
-/* 'closed' and 'mode' are attributes for backwards compatibility reasons. */
-
-static PyObject *
-get_closed(PyFileIOObject *self, void *closure)
-{
-	return PyBool_FromLong((long)(self->fd < 0));
-}
-
-static PyObject *
-get_closefd(PyFileIOObject *self, void *closure)
-{
-	return PyBool_FromLong((long)(self->closefd));
-}
-
-static PyObject *
-get_mode(PyFileIOObject *self, void *closure)
-{
-	return PyUnicode_FromString(mode_string(self));
-}
-
-static PyGetSetDef fileio_getsetlist[] = {
-	{"closed", (getter)get_closed, NULL, "True if the file is closed"},
-	{"closefd", (getter)get_closefd, NULL, 
-		"True if the file descriptor will be closed"},
-	{"mode", (getter)get_mode, NULL, "String giving the file mode"},
-	{0},
-};
-
-PyTypeObject PyFileIO_Type = {
-	PyVarObject_HEAD_INIT(NULL, 0)
-	"_io.FileIO",
-	sizeof(PyFileIOObject),
-	0,
-	(destructor)fileio_dealloc,		/* tp_dealloc */
-	0,					/* tp_print */
-	0,					/* tp_getattr */
-	0,					/* tp_setattr */
-	0,					/* tp_reserved */
-	(reprfunc)fileio_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 | Py_TPFLAGS_BASETYPE
-			| Py_TPFLAGS_HAVE_GC,	/* tp_flags */
-	fileio_doc,				/* tp_doc */
-	(traverseproc)fileio_traverse,		/* tp_traverse */
-	(inquiry)fileio_clear,			/* tp_clear */
-	0,					/* tp_richcompare */
-	offsetof(PyFileIOObject, weakreflist),	/* tp_weaklistoffset */
-	0,					/* tp_iter */
-	0,					/* tp_iternext */
-	fileio_methods,				/* tp_methods */
-	0,					/* tp_members */
-	fileio_getsetlist,			/* tp_getset */
-	0,					/* tp_base */
-	0,					/* tp_dict */
-	0,					/* tp_descr_get */
-	0,					/* tp_descr_set */
-	offsetof(PyFileIOObject, dict), /* tp_dictoffset */
-	fileio_init,				/* tp_init */
-	PyType_GenericAlloc,			/* tp_alloc */
-	fileio_new,				/* tp_new */
-	PyObject_GC_Del,			/* tp_free */
-};
Modified: python/branches/py3k-short-float-repr/Modules/_functoolsmodule.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/_functoolsmodule.c	(original)
+++ python/branches/py3k-short-float-repr/Modules/_functoolsmodule.c	Sun Apr 5 01:04:14 2009
@@ -196,6 +196,53 @@
 	{NULL} /* Sentinel */
 };
 
+/* Pickle strategy:
+ __reduce__ by itself doesn't support getting kwargs in the unpickle
+ operation so we define a __setstate__ that replaces all the information
+ about the partial. If we only replaced part of it someone would use
+ it as a hook to do stange things.
+ */
+
+PyObject *
+partial_reduce(partialobject *pto, PyObject *unused)
+{
+	return Py_BuildValue("O(O)(OOOO)", Py_TYPE(pto), pto->fn, pto->fn, 
+			 pto->args, pto->kw,
+			 pto->dict ? pto->dict : Py_None);
+}
+
+PyObject *
+partial_setstate(partialobject *pto, PyObject *args)
+{
+	PyObject *fn, *fnargs, *kw, *dict;
+	if (!PyArg_ParseTuple(args, "(OOOO):__setstate__", 
+			 &fn, &fnargs, &kw, &dict))
+		return NULL;
+	Py_XDECREF(pto->fn);
+	Py_XDECREF(pto->args);
+	Py_XDECREF(pto->kw);
+	Py_XDECREF(pto->dict);
+	pto->fn = fn;
+	pto->args = fnargs;
+	pto->kw = kw;
+	if (dict != Py_None) {
+	 pto->dict = dict;
+	 Py_INCREF(dict);
+	} else {
+	 pto->dict = NULL;
+	}
+	Py_INCREF(fn);
+	Py_INCREF(fnargs);
+	Py_INCREF(kw);
+	Py_RETURN_NONE;
+}
+
+static PyMethodDef partial_methods[] = {
+	{"__reduce__", (PyCFunction)partial_reduce, METH_NOARGS},
+	{"__setstate__", (PyCFunction)partial_setstate, METH_VARARGS},
+	{NULL,		NULL}		/* sentinel */
+};
+
 static PyTypeObject partial_type = {
 	PyVarObject_HEAD_INIT(NULL, 0)
 	"functools.partial",		/* tp_name */
@@ -226,7 +273,7 @@
 	offsetof(partialobject, weakreflist),	/* tp_weaklistoffset */
 	0,				/* tp_iter */
 	0,				/* tp_iternext */
-	0,				/* tp_methods */
+	partial_methods,		/* tp_methods */
 	partial_memberlist,		/* tp_members */
 	partial_getsetlist,		/* tp_getset */
 	0,				/* tp_base */
Deleted: python/branches/py3k-short-float-repr/Modules/_iobase.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/_iobase.c	Sun Apr 5 01:04:14 2009
+++ (empty file)
@@ -1,894 +0,0 @@
-/*
- An implementation of the I/O abstract base classes hierarchy
- as defined by PEP 3116 - "New I/O"
- 
- Classes defined here: IOBase, RawIOBase.
- 
- Written by Amaury Forgeot d'Arc and Antoine Pitrou
-*/
-
-
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "structmember.h"
-#include "_iomodule.h"
-
-/*
- * IOBase class, an abstract class
- */
-
-typedef struct {
- PyObject_HEAD
- 
- PyObject *dict;
- PyObject *weakreflist;
-} IOBaseObject;
-
-PyDoc_STRVAR(IOBase_doc,
- "The abstract base class for all I/O classes, acting on streams of\n"
- "bytes. There is no public constructor.\n"
- "\n"
- "This class provides dummy implementations for many methods that\n"
- "derived classes can override selectively; the default implementations\n"
- "represent a file that cannot be read, written or seeked.\n"
- "\n"
- "Even though IOBase does not declare read, readinto, or write because\n"
- "their signatures will vary, implementations and clients should\n"
- "consider those methods part of the interface. Also, implementations\n"
- "may raise a IOError when operations they do not support are called.\n"
- "\n"
- "The basic type used for binary data read from or written to a file is\n"
- "bytes. bytearrays are accepted too, and in some cases (such as\n"
- "readinto) needed. Text I/O classes work with str data.\n"
- "\n"
- "Note that calling any method (even inquiries) on a closed stream is\n"
- "undefined. Implementations may raise IOError in this case.\n"
- "\n"
- "IOBase (and its subclasses) support the iterator protocol, meaning\n"
- "that an IOBase object can be iterated over yielding the lines in a\n"
- "stream.\n"
- "\n"
- "IOBase also supports the :keyword:`with` statement. In this example,\n"
- "fp is closed after the suite of the with statment is complete:\n"
- "\n"
- "with open('spam.txt', 'r') as fp:\n"
- " fp.write('Spam and eggs!')\n");
-
-/* Use this macro whenever you want to check the internal `closed` status
- of the IOBase object rather than the virtual `closed` attribute as returned
- by whatever subclass. */
-
-#define IS_CLOSED(self) \
- PyObject_HasAttrString(self, "__IOBase_closed")
-
-/* Internal methods */
-static PyObject *
-IOBase_unsupported(const char *message)
-{
- PyErr_SetString(IO_STATE->unsupported_operation, message);
- return NULL;
-}
-
-/* Positionning */
-
-PyDoc_STRVAR(IOBase_seek_doc,
- "Change stream position.\n"
- "\n"
- "Change the stream position to byte offset offset. offset is\n"
- "interpreted relative to the position indicated by whence. Values\n"
- "for whence are:\n"
- "\n"
- "* 0 -- start of stream (the default); offset should be zero or positive\n"
- "* 1 -- current stream position; offset may be negative\n"
- "* 2 -- end of stream; offset is usually negative\n"
- "\n"
- "Return the new absolute position.");
-
-static PyObject *
-IOBase_seek(PyObject *self, PyObject *args)
-{
- return IOBase_unsupported("seek");
-}
-
-PyDoc_STRVAR(IOBase_tell_doc,
- "Return current stream position.");
-
-static PyObject *
-IOBase_tell(PyObject *self, PyObject *args)
-{
- return PyObject_CallMethod(self, "seek", "ii", 0, 1);
-}
-
-PyDoc_STRVAR(IOBase_truncate_doc,
- "Truncate file to size bytes.\n"
- "\n"
- "Size defaults to the current IO position as reported by tell(). Return\n"
- "the new size.");
-
-static PyObject *
-IOBase_truncate(PyObject *self, PyObject *args)
-{
- return IOBase_unsupported("truncate");
-}
-
-/* Flush and close methods */
-
-PyDoc_STRVAR(IOBase_flush_doc,
- "Flush write buffers, if applicable.\n"
- "\n"
- "This is not implemented for read-only and non-blocking streams.\n");
-
-static PyObject *
-IOBase_flush(PyObject *self, PyObject *args)
-{
- /* XXX Should this return the number of bytes written??? */
- if (IS_CLOSED(self)) {
- PyErr_SetString(PyExc_ValueError, "I/O operation on closed file.");
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(IOBase_close_doc,
- "Flush and close the IO object.\n"
- "\n"
- "This method has no effect if the file is already closed.\n");
-
-static int
-IOBase_closed(PyObject *self)
-{
- PyObject *res;
- int closed;
- /* This gets the derived attribute, which is *not* __IOBase_closed
- in most cases! */
- res = PyObject_GetAttr(self, _PyIO_str_closed);
- if (res == NULL)
- return 0;
- closed = PyObject_IsTrue(res);
- Py_DECREF(res);
- return closed;
-}
-
-static PyObject *
-IOBase_closed_get(PyObject *self, void *context)
-{
- return PyBool_FromLong(IS_CLOSED(self));
-}
-
-PyObject *
-_PyIOBase_checkClosed(PyObject *self, PyObject *args)
-{
- if (IOBase_closed(self)) {
- PyErr_SetString(PyExc_ValueError, "I/O operation on closed file.");
- return NULL;
- }
- if (args == Py_True)
- return Py_None;
- else
- Py_RETURN_NONE;
-}
-
-/* XXX: IOBase thinks it has to maintain its own internal state in
- `__IOBase_closed` and call flush() by itself, but it is redundant with
- whatever behaviour a non-trivial derived class will implement. */
-
-static PyObject *
-IOBase_close(PyObject *self, PyObject *args)
-{
- PyObject *res;
-
- if (IS_CLOSED(self))
- Py_RETURN_NONE;
-
- res = PyObject_CallMethodObjArgs(self, _PyIO_str_flush, NULL);
- PyObject_SetAttrString(self, "__IOBase_closed", Py_True);
- if (res == NULL) {
- /* If flush() fails, just give up */
- if (PyErr_ExceptionMatches(PyExc_IOError))
- PyErr_Clear();
- else
- return NULL;
- }
- Py_XDECREF(res);
- Py_RETURN_NONE;
-}
-
-/* Finalization and garbage collection support */
-
-int
-_PyIOBase_finalize(PyObject *self)
-{
- PyObject *res;
- PyObject *tp, *v, *tb;
- int closed = 1;
- int is_zombie;
-
- /* If _PyIOBase_finalize() is called from a destructor, we need to
- resurrect the object as calling close() can invoke arbitrary code. */
- is_zombie = (Py_REFCNT(self) == 0);
- if (is_zombie) {
- ++Py_REFCNT(self);
- }
- PyErr_Fetch(&tp, &v, &tb);
- /* If `closed` doesn't exist or can't be evaluated as bool, then the
- object is probably in an unusable state, so ignore. */
- res = PyObject_GetAttr(self, _PyIO_str_closed);
- if (res == NULL)
- PyErr_Clear();
- else {
- closed = PyObject_IsTrue(res);
- Py_DECREF(res);
- if (closed == -1)
- PyErr_Clear();
- }
- if (closed == 0) {
- res = PyObject_CallMethodObjArgs((PyObject *) self, _PyIO_str_close,
- NULL);
- /* Silencing I/O errors is bad, but printing spurious tracebacks is
- equally as bad, and potentially more frequent (because of
- shutdown issues). */
- if (res == NULL)
- PyErr_Clear();
- else
- Py_DECREF(res);
- }
- PyErr_Restore(tp, v, tb);
- if (is_zombie) {
- if (--Py_REFCNT(self) != 0) {
- /* The object lives again. The following code is taken from
- slot_tp_del in typeobject.c. */
- Py_ssize_t refcnt = Py_REFCNT(self);
- _Py_NewReference(self);
- Py_REFCNT(self) = refcnt;
- /* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so
- * we need to undo that. */
- _Py_DEC_REFTOTAL;
- /* If Py_TRACE_REFS, _Py_NewReference re-added self to the object
- * chain, so no more to do there.
- * If COUNT_ALLOCS, the original decref bumped tp_frees, and
- * _Py_NewReference bumped tp_allocs: both of those need to be
- * undone.
- */
-#ifdef COUNT_ALLOCS
- --Py_TYPE(self)->tp_frees;
- --Py_TYPE(self)->tp_allocs;
-#endif
- return -1;
- }
- }
- return 0;
-}
-
-static int
-IOBase_traverse(IOBaseObject *self, visitproc visit, void *arg)
-{
- Py_VISIT(self->dict);
- return 0;
-}
-
-static int
-IOBase_clear(IOBaseObject *self)
-{
- if (_PyIOBase_finalize((PyObject *) self) < 0)
- return -1;
- Py_CLEAR(self->dict);
- return 0;
-}
-
-/* Destructor */
-
-static void
-IOBase_dealloc(IOBaseObject *self)
-{
- /* NOTE: since IOBaseObject has its own dict, Python-defined attributes
- are still available here for close() to use.
- However, if the derived class declares a __slots__, those slots are
- already gone.
- */
- if (_PyIOBase_finalize((PyObject *) self) < 0) {
- /* When called from a heap type's dealloc, the type will be
- decref'ed on return (see e.g. subtype_dealloc in typeobject.c). */
- if (PyType_HasFeature(Py_TYPE(self), Py_TPFLAGS_HEAPTYPE))
- Py_INCREF(Py_TYPE(self));
- return;
- }
- _PyObject_GC_UNTRACK(self);
- if (self->weakreflist != NULL)
- PyObject_ClearWeakRefs((PyObject *) self);
- Py_CLEAR(self->dict);
- Py_TYPE(self)->tp_free((PyObject *) self);
-}
-
-/* Inquiry methods */
-
-PyDoc_STRVAR(IOBase_seekable_doc,
- "Return whether object supports random access.\n"
- "\n"
- "If False, seek(), tell() and truncate() will raise IOError.\n"
- "This method may need to do a test seek().");
-
-static PyObject *
-IOBase_seekable(PyObject *self, PyObject *args)
-{
- Py_RETURN_FALSE;
-}
-
-PyObject *
-_PyIOBase_checkSeekable(PyObject *self, PyObject *args)
-{
- PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_seekable, NULL);
- if (res == NULL)
- return NULL;
- if (res != Py_True) {
- Py_CLEAR(res);
- PyErr_SetString(PyExc_IOError, "File or stream is not seekable.");
- return NULL;
- }
- if (args == Py_True) {
- Py_DECREF(res);
- }
- return res;
-}
-
-PyDoc_STRVAR(IOBase_readable_doc,
- "Return whether object was opened for reading.\n"
- "\n"
- "If False, read() will raise IOError.");
-
-static PyObject *
-IOBase_readable(PyObject *self, PyObject *args)
-{
- Py_RETURN_FALSE;
-}
-
-/* May be called with any object */
-PyObject *
-_PyIOBase_checkReadable(PyObject *self, PyObject *args)
-{
- PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_readable, NULL);
- if (res == NULL)
- return NULL;
- if (res != Py_True) {
- Py_CLEAR(res);
- PyErr_SetString(PyExc_IOError, "File or stream is not readable.");
- return NULL;
- }
- if (args == Py_True) {
- Py_DECREF(res);
- }
- return res;
-}
-
-PyDoc_STRVAR(IOBase_writable_doc,
- "Return whether object was opened for writing.\n"
- "\n"
- "If False, read() will raise IOError.");
-
-static PyObject *
-IOBase_writable(PyObject *self, PyObject *args)
-{
- Py_RETURN_FALSE;
-}
-
-/* May be called with any object */
-PyObject *
-_PyIOBase_checkWritable(PyObject *self, PyObject *args)
-{
- PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_writable, NULL);
- if (res == NULL)
- return NULL;
- if (res != Py_True) {
- Py_CLEAR(res);
- PyErr_SetString(PyExc_IOError, "File or stream is not writable.");
- return NULL;
- }
- if (args == Py_True) {
- Py_DECREF(res);
- }
- return res;
-}
-
-/* Context manager */
-
-static PyObject *
-IOBase_enter(PyObject *self, PyObject *args)
-{
- if (_PyIOBase_checkClosed(self, Py_True) == NULL)
- return NULL;
-
- Py_INCREF(self);
- return self;
-}
-
-static PyObject *
-IOBase_exit(PyObject *self, PyObject *args)
-{
- return PyObject_CallMethodObjArgs(self, _PyIO_str_close, NULL);
-}
-
-/* Lower-level APIs */
-
-/* XXX Should these be present even if unimplemented? */
-
-PyDoc_STRVAR(IOBase_fileno_doc,
- "Returns underlying file descriptor if one exists.\n"
- "\n"
- "An IOError is raised if the IO object does not use a file descriptor.\n");
-
-static PyObject *
-IOBase_fileno(PyObject *self, PyObject *args)
-{
- return IOBase_unsupported("fileno");
-}
-
-PyDoc_STRVAR(IOBase_isatty_doc,
- "Return whether this is an 'interactive' stream.\n"
- "\n"
- "Return False if it can't be determined.\n");
-
-static PyObject *
-IOBase_isatty(PyObject *self, PyObject *args)
-{
- if (_PyIOBase_checkClosed(self, Py_True) == NULL)
- return NULL;
- Py_RETURN_FALSE;
-}
-
-/* Readline(s) and writelines */
-
-PyDoc_STRVAR(IOBase_readline_doc,
- "Read and return a line from the stream.\n"
- "\n"
- "If limit is specified, at most limit bytes will be read.\n"
- "\n"
- "The line terminator is always b'\n' for binary files; for text\n"
- "files, the newlines argument to open can be used to select the line\n"
- "terminator(s) recognized.\n");
-
-static PyObject *
-IOBase_readline(PyObject *self, PyObject *args)
-{
- /* For backwards compatibility, a (slowish) readline(). */
-
- Py_ssize_t limit = -1;
- int has_peek = 0;
- PyObject *buffer, *result;
- Py_ssize_t old_size = -1;
-
- if (!PyArg_ParseTuple(args, "|n:readline", &limit)) {
- return NULL;
- }
-
- if (PyObject_HasAttrString(self, "peek"))
- has_peek = 1;
-
- buffer = PyByteArray_FromStringAndSize(NULL, 0);
- if (buffer == NULL)
- return NULL;
-
- while (limit < 0 || Py_SIZE(buffer) < limit) {
- Py_ssize_t nreadahead = 1;
- PyObject *b;
-
- if (has_peek) {
- PyObject *readahead = PyObject_CallMethod(self, "peek", "i", 1);
- if (readahead == NULL)
- goto fail;
- if (!PyBytes_Check(readahead)) {
- PyErr_Format(PyExc_IOError,
- "peek() should have returned a bytes object, "
- "not '%.200s'", Py_TYPE(readahead)->tp_name);
- Py_DECREF(readahead);
- goto fail;
- }
- if (PyBytes_GET_SIZE(readahead) > 0) {
- Py_ssize_t n = 0;
- const char *buf = PyBytes_AS_STRING(readahead);
- if (limit >= 0) {
- do {
- if (n >= PyBytes_GET_SIZE(readahead) || n >= limit)
- break;
- if (buf[n++] == '\n')
- break;
- } while (1);
- }
- else {
- do {
- if (n >= PyBytes_GET_SIZE(readahead))
- break;
- if (buf[n++] == '\n')
- break;
- } while (1);
- }
- nreadahead = n;
- }
- Py_DECREF(readahead);
- }
-
- b = PyObject_CallMethod(self, "read", "n", nreadahead);
- if (b == NULL)
- goto fail;
- if (!PyBytes_Check(b)) {
- PyErr_Format(PyExc_IOError,
- "read() should have returned a bytes object, "
- "not '%.200s'", Py_TYPE(b)->tp_name);
- Py_DECREF(b);
- goto fail;
- }
- if (PyBytes_GET_SIZE(b) == 0) {
- Py_DECREF(b);
- break;
- }
-
- old_size = PyByteArray_GET_SIZE(buffer);
- PyByteArray_Resize(buffer, old_size + PyBytes_GET_SIZE(b));
- memcpy(PyByteArray_AS_STRING(buffer) + old_size,
- PyBytes_AS_STRING(b), PyBytes_GET_SIZE(b));
-
- Py_DECREF(b);
-
- if (PyByteArray_AS_STRING(buffer)[PyByteArray_GET_SIZE(buffer) - 1] == '\n')
- break;
- }
-
- result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(buffer),
- PyByteArray_GET_SIZE(buffer));
- Py_DECREF(buffer);
- return result;
- fail:
- Py_DECREF(buffer);
- return NULL;
-}
-
-static PyObject *
-IOBase_iter(PyObject *self)
-{
- if (_PyIOBase_checkClosed(self, Py_True) == NULL)
- return NULL;
-
- Py_INCREF(self);
- return self;
-}
-
-static PyObject *
-IOBase_iternext(PyObject *self)
-{
- PyObject *line = PyObject_CallMethodObjArgs(self, _PyIO_str_readline, NULL);
-
- if (line == NULL)
- return NULL;
-
- if (PyObject_Size(line) == 0) {
- Py_DECREF(line);
- return NULL;
- }
-
- return line;
-}
-
-PyDoc_STRVAR(IOBase_readlines_doc,
- "Return a list of lines from the stream.\n"
- "\n"
- "hint can be specified to control the number of lines read: no more\n"
- "lines will be read if the total size (in bytes/characters) of all\n"
- "lines so far exceeds hint.");
-
-static PyObject *
-IOBase_readlines(PyObject *self, PyObject *args)
-{
- Py_ssize_t hint = -1, length = 0;
- PyObject *hintobj = Py_None, *result;
-
- if (!PyArg_ParseTuple(args, "|O:readlines", &hintobj)) {
- return NULL;
- }
- if (hintobj != Py_None) {
- hint = PyNumber_AsSsize_t(hintobj, PyExc_ValueError);
- if (hint == -1 && PyErr_Occurred())
- return NULL;
- }
-
- result = PyList_New(0);
- if (result == NULL)
- return NULL;
-
- if (hint <= 0) {
- /* XXX special-casing this made sense in the Python version in order
- to remove the bytecode interpretation overhead, but it could
- probably be removed here. */
- PyObject *ret = PyObject_CallMethod(result, "extend", "O", self);
- if (ret == NULL) {
- Py_DECREF(result);
- return NULL;
- }
- Py_DECREF(ret);
- return result;
- }
-
- while (1) {
- PyObject *line = PyIter_Next(self);
- if (line == NULL) {
- if (PyErr_Occurred()) {
- Py_DECREF(result);
- return NULL;
- }
- else
- break; /* StopIteration raised */
- }
-
- if (PyList_Append(result, line) < 0) {
- Py_DECREF(line);
- Py_DECREF(result);
- return NULL;
- }
- length += PyObject_Size(line);
- Py_DECREF(line);
-
- if (length > hint)
- break;
- }
- return result;
-}
-
-static PyObject *
-IOBase_writelines(PyObject *self, PyObject *args)
-{
- PyObject *lines, *iter, *res;
-
- if (!PyArg_ParseTuple(args, "O:writelines", &lines)) {
- return NULL;
- }
-
- if (_PyIOBase_checkClosed(self, Py_True) == NULL)
- return NULL;
-
- iter = PyObject_GetIter(lines);
- if (iter == NULL)
- return NULL;
-
- while (1) {
- PyObject *line = PyIter_Next(iter);
- if (line == NULL) {
- if (PyErr_Occurred()) {
- Py_DECREF(iter);
- return NULL;
- }
- else
- break; /* Stop Iteration */
- }
-
- res = PyObject_CallMethodObjArgs(self, _PyIO_str_write, line, NULL);
- Py_DECREF(line);
- if (res == NULL) {
- Py_DECREF(iter);
- return NULL;
- }
- Py_DECREF(res);
- }
- Py_DECREF(iter);
- Py_RETURN_NONE;
-}
-
-static PyMethodDef IOBase_methods[] = {
- {"seek", IOBase_seek, METH_VARARGS, IOBase_seek_doc},
- {"tell", IOBase_tell, METH_NOARGS, IOBase_tell_doc},
- {"truncate", IOBase_truncate, METH_VARARGS, IOBase_truncate_doc},
- {"flush", IOBase_flush, METH_NOARGS, IOBase_flush_doc},
- {"close", IOBase_close, METH_NOARGS, IOBase_close_doc},
-
- {"seekable", IOBase_seekable, METH_NOARGS, IOBase_seekable_doc},
- {"readable", IOBase_readable, METH_NOARGS, IOBase_readable_doc},
- {"writable", IOBase_writable, METH_NOARGS, IOBase_writable_doc},
-
- {"_checkClosed", _PyIOBase_checkClosed, METH_NOARGS},
- {"_checkSeekable", _PyIOBase_checkSeekable, METH_NOARGS},
- {"_checkReadable", _PyIOBase_checkReadable, METH_NOARGS},
- {"_checkWritable", _PyIOBase_checkWritable, METH_NOARGS},
-
- {"fileno", IOBase_fileno, METH_NOARGS, IOBase_fileno_doc},
- {"isatty", IOBase_isatty, METH_NOARGS, IOBase_isatty_doc},
-
- {"__enter__", IOBase_enter, METH_NOARGS},
- {"__exit__", IOBase_exit, METH_VARARGS},
-
- {"readline", IOBase_readline, METH_VARARGS, IOBase_readline_doc},
- {"readlines", IOBase_readlines, METH_VARARGS, IOBase_readlines_doc},
- {"writelines", IOBase_writelines, METH_VARARGS},
-
- {NULL, NULL}
-};
-
-static PyGetSetDef IOBase_getset[] = {
- {"closed", (getter)IOBase_closed_get, NULL, NULL},
- {0}
-};
-
-
-PyTypeObject PyIOBase_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "_io._IOBase", /*tp_name*/
- sizeof(IOBaseObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)IOBase_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 | Py_TPFLAGS_BASETYPE
- | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
- IOBase_doc, /* tp_doc */
- (traverseproc)IOBase_traverse, /* tp_traverse */
- (inquiry)IOBase_clear, /* tp_clear */
- 0, /* tp_richcompare */
- offsetof(IOBaseObject, weakreflist), /* tp_weaklistoffset */
- IOBase_iter, /* tp_iter */
- IOBase_iternext, /* tp_iternext */
- IOBase_methods, /* tp_methods */
- 0, /* tp_members */
- IOBase_getset, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- offsetof(IOBaseObject, dict), /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- PyType_GenericNew, /* tp_new */
-};
-
-
-/*
- * RawIOBase class, Inherits from IOBase.
- */
-PyDoc_STRVAR(RawIOBase_doc,
- "Base class for raw binary I/O.");
-
-/*
- * The read() method is implemented by calling readinto(); derived classes
- * that want to support read() only need to implement readinto() as a
- * primitive operation. In general, readinto() can be more efficient than
- * read().
- *
- * (It would be tempting to also provide an implementation of readinto() in
- * terms of read(), in case the latter is a more suitable primitive operation,
- * but that would lead to nasty recursion in case a subclass doesn't implement
- * either.)
-*/
-
-static PyObject *
-RawIOBase_read(PyObject *self, PyObject *args)
-{
- Py_ssize_t n = -1;
- PyObject *b, *res;
-
- if (!PyArg_ParseTuple(args, "|n:read", &n)) {
- return NULL;
- }
-
- if (n < 0)
- return PyObject_CallMethod(self, "readall", NULL);
-
- /* TODO: allocate a bytes object directly instead and manually construct
- a writable memoryview pointing to it. */
- b = PyByteArray_FromStringAndSize(NULL, n);
- if (b == NULL)
- return NULL;
-
- res = PyObject_CallMethodObjArgs(self, _PyIO_str_readinto, b, NULL);
- if (res == NULL) {
- Py_DECREF(b);
- return NULL;
- }
-
- n = PyNumber_AsSsize_t(res, PyExc_ValueError);
- Py_DECREF(res);
- if (n == -1 && PyErr_Occurred()) {
- Py_DECREF(b);
- return NULL;
- }
-
- res = PyBytes_FromStringAndSize(PyByteArray_AsString(b), n);
- Py_DECREF(b);
- return res;
-}
-
-
-PyDoc_STRVAR(RawIOBase_readall_doc,
- "Read until EOF, using multiple read() call.");
-
-static PyObject *
-RawIOBase_readall(PyObject *self, PyObject *args)
-{
- int r;
- PyObject *chunks = PyList_New(0);
- PyObject *result;
- 
- if (chunks == NULL)
- return NULL;
-
- while (1) {
- PyObject *data = PyObject_CallMethod(self, "read",
- "i", DEFAULT_BUFFER_SIZE);
- if (!data) {
- Py_DECREF(chunks);
- return NULL;
- }
- if (!PyBytes_Check(data)) {
- Py_DECREF(chunks);
- Py_DECREF(data);
- PyErr_SetString(PyExc_TypeError, "read() should return bytes");
- return NULL;
- }
- if (PyBytes_GET_SIZE(data) == 0) {
- /* EOF */
- Py_DECREF(data);
- break;
- }
- r = PyList_Append(chunks, data);
- Py_DECREF(data);
- if (r < 0) {
- Py_DECREF(chunks);
- return NULL;
- }
- }
- result = _PyBytes_Join(_PyIO_empty_bytes, chunks);
- Py_DECREF(chunks);
- return result;
-}
-
-static PyMethodDef RawIOBase_methods[] = {
- {"read", RawIOBase_read, METH_VARARGS},
- {"readall", RawIOBase_readall, METH_NOARGS, RawIOBase_readall_doc},
- {NULL, NULL}
-};
-
-PyTypeObject PyRawIOBase_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "_io._RawIOBase", /*tp_name*/
- 0, /*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, /*tp_flags*/
- RawIOBase_doc, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- RawIOBase_methods, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- &PyIOBase_Type, /* 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 */
-};
Deleted: python/branches/py3k-short-float-repr/Modules/_iomodule.h
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/_iomodule.h	Sun Apr 5 01:04:14 2009
+++ (empty file)
@@ -1,150 +0,0 @@
-/*
- * Declarations shared between the different parts of the io module
- */
-
-/* ABCs */
-extern PyTypeObject PyIOBase_Type;
-extern PyTypeObject PyRawIOBase_Type;
-extern PyTypeObject PyBufferedIOBase_Type;
-extern PyTypeObject PyTextIOBase_Type;
-
-/* Concrete classes */
-extern PyTypeObject PyFileIO_Type;
-extern PyTypeObject PyBytesIO_Type;
-extern PyTypeObject PyStringIO_Type;
-extern PyTypeObject PyBufferedReader_Type;
-extern PyTypeObject PyBufferedWriter_Type;
-extern PyTypeObject PyBufferedRWPair_Type;
-extern PyTypeObject PyBufferedRandom_Type;
-extern PyTypeObject PyTextIOWrapper_Type;
-extern PyTypeObject PyIncrementalNewlineDecoder_Type;
-
-/* These functions are used as METH_NOARGS methods, are normally called
- * with args=NULL, and return a new reference.
- * BUT when args=Py_True is passed, they return a borrowed reference.
- */
-extern PyObject* _PyIOBase_checkReadable(PyObject *self, PyObject *args);
-extern PyObject* _PyIOBase_checkWritable(PyObject *self, PyObject *args);
-extern PyObject* _PyIOBase_checkSeekable(PyObject *self, PyObject *args);
-extern PyObject* _PyIOBase_checkClosed(PyObject *self, PyObject *args);
-
-/* Helper for finalization.
- This function will revive an object ready to be deallocated and try to
- close() it. It returns 0 if the object can be destroyed, or -1 if it
- is alive again. */
-extern int _PyIOBase_finalize(PyObject *self);
-
-/* Returns true if the given FileIO object is closed.
- Doesn't check the argument type, so be careful! */
-extern int _PyFileIO_closed(PyObject *self);
-
-/* Shortcut to the core of the IncrementalNewlineDecoder.decode method */
-extern PyObject *_PyIncrementalNewlineDecoder_decode(
- PyObject *self, PyObject *input, int final);
-
-/* Finds the first line ending between `start` and `end`.
- If found, returns the index after the line ending and doesn't touch
- `*consumed`.
- If not found, returns -1 and sets `*consumed` to the number of characters
- which can be safely put aside until another search.
- 
- NOTE: for performance reasons, `end` must point to a NUL character ('0円'). 
- Otherwise, the function will scan further and return garbage. */
-extern Py_ssize_t _PyIO_find_line_ending(
- int translated, int universal, PyObject *readnl,
- Py_UNICODE *start, Py_UNICODE *end, Py_ssize_t *consumed);
-
-
-#define DEFAULT_BUFFER_SIZE (8 * 1024) /* bytes */
-
-typedef struct {
- PyException_HEAD
- PyObject *myerrno;
- PyObject *strerror;
- PyObject *filename; /* Not used, but part of the IOError object */
- Py_ssize_t written;
-} PyBlockingIOErrorObject;
-PyAPI_DATA(PyObject *) PyExc_BlockingIOError;
-
-/*
- * Offset type for positioning.
- */
-
-#if defined(MS_WIN64) || defined(MS_WINDOWS)
-
-/* Windows uses long long for offsets */
-typedef PY_LONG_LONG Py_off_t;
-# define PyLong_AsOff_t PyLong_AsLongLong
-# define PyLong_FromOff_t PyLong_FromLongLong
-# define PY_OFF_T_MAX PY_LLONG_MAX
-# define PY_OFF_T_MIN PY_LLONG_MIN
-
-#else
-
-/* Other platforms use off_t */
-typedef off_t Py_off_t;
-#if (SIZEOF_OFF_T == SIZEOF_SIZE_T)
-# define PyLong_AsOff_t PyLong_AsSsize_t
-# define PyLong_FromOff_t PyLong_FromSsize_t
-# define PY_OFF_T_MAX PY_SSIZE_T_MAX
-# define PY_OFF_T_MIN PY_SSIZE_T_MIN
-#elif (SIZEOF_OFF_T == SIZEOF_LONG_LONG)
-# define PyLong_AsOff_t PyLong_AsLongLong
-# define PyLong_FromOff_t PyLong_FromLongLong
-# define PY_OFF_T_MAX PY_LLONG_MAX
-# define PY_OFF_T_MIN PY_LLONG_MIN
-#elif (SIZEOF_OFF_T == SIZEOF_LONG)
-# define PyLong_AsOff_t PyLong_AsLong
-# define PyLong_FromOff_t PyLong_FromLong
-# define PY_OFF_T_MAX LONG_MAX
-# define PY_OFF_T_MIN LONG_MIN
-#else
-# error off_t does not match either size_t, long, or long long!
-#endif
-
-#endif
-
-extern Py_off_t PyNumber_AsOff_t(PyObject *item, PyObject *err);
-
-/* Implementation details */
-
-/* IO module structure */
-
-extern PyModuleDef _PyIO_Module;
-
-typedef struct {
- int initialized;
- PyObject *os_module;
- PyObject *locale_module;
-
- PyObject *unsupported_operation;
-} _PyIO_State;
-
-#define IO_MOD_STATE(mod) ((_PyIO_State *)PyModule_GetState(mod))
-#define IO_STATE IO_MOD_STATE(PyState_FindModule(&_PyIO_Module))
-
-extern PyObject *_PyIO_str_close;
-extern PyObject *_PyIO_str_closed;
-extern PyObject *_PyIO_str_decode;
-extern PyObject *_PyIO_str_encode;
-extern PyObject *_PyIO_str_fileno;
-extern PyObject *_PyIO_str_flush;
-extern PyObject *_PyIO_str_getstate;
-extern PyObject *_PyIO_str_isatty;
-extern PyObject *_PyIO_str_newlines;
-extern PyObject *_PyIO_str_nl;
-extern PyObject *_PyIO_str_read;
-extern PyObject *_PyIO_str_read1;
-extern PyObject *_PyIO_str_readable;
-extern PyObject *_PyIO_str_readinto;
-extern PyObject *_PyIO_str_readline;
-extern PyObject *_PyIO_str_reset;
-extern PyObject *_PyIO_str_seek;
-extern PyObject *_PyIO_str_seekable;
-extern PyObject *_PyIO_str_tell;
-extern PyObject *_PyIO_str_truncate;
-extern PyObject *_PyIO_str_writable;
-extern PyObject *_PyIO_str_write;
-
-extern PyObject *_PyIO_empty_str;
-extern PyObject *_PyIO_empty_bytes;
Modified: python/branches/py3k-short-float-repr/Modules/_multiprocessing/multiprocessing.h
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/_multiprocessing/multiprocessing.h	(original)
+++ python/branches/py3k-short-float-repr/Modules/_multiprocessing/multiprocessing.h	Sun Apr 5 01:04:14 2009
@@ -16,6 +16,9 @@
 # include <windows.h>
 # include <winsock2.h>
 # include <process.h>		 /* getpid() */
+# ifdef Py_DEBUG
+# include <crtdbg.h>
+# endif
 # define SEM_HANDLE HANDLE
 # define SEM_VALUE_MAX LONG_MAX
 #else
Modified: python/branches/py3k-short-float-repr/Modules/_multiprocessing/semaphore.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/_multiprocessing/semaphore.c	(original)
+++ python/branches/py3k-short-float-repr/Modules/_multiprocessing/semaphore.c	Sun Apr 5 01:04:14 2009
@@ -546,7 +546,7 @@
 	 "acquire the semaphore/lock"},
 	{"release", (PyCFunction)semlock_release, METH_NOARGS, 
 	 "release the semaphore/lock"},
-	{"__enter__", (PyCFunction)semlock_acquire, METH_VARARGS,
+ {"__enter__", (PyCFunction)semlock_acquire, METH_VARARGS | METH_KEYWORDS,
 	 "enter the semaphore/lock"},
 	{"__exit__", (PyCFunction)semlock_release, METH_VARARGS, 
 	 "exit the semaphore/lock"},
Modified: python/branches/py3k-short-float-repr/Modules/_multiprocessing/win32_functions.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/_multiprocessing/win32_functions.c	(original)
+++ python/branches/py3k-short-float-repr/Modules/_multiprocessing/win32_functions.c	Sun Apr 5 01:04:14 2009
@@ -130,6 +130,12 @@
 	if (!PyArg_ParseTuple(args, "I", &uExitCode))
 		return NULL;
 
+	#if defined(Py_DEBUG)
+		SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOALIGNMENTFAULTEXCEPT|SEM_NOGPFAULTERRORBOX|SEM_NOOPENFILEERRORBOX);
+		_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
+	#endif
+
+
 	ExitProcess(uExitCode);
 
 	return NULL;
Modified: python/branches/py3k-short-float-repr/Modules/_pickle.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/_pickle.c	(original)
+++ python/branches/py3k-short-float-repr/Modules/_pickle.c	Sun Apr 5 01:04:14 2009
@@ -691,9 +691,9 @@
 
 module_name = PyObject_GetAttr(global, module_str);
 
- /* In some rare cases (e.g., random.getrandbits), __module__ can be
- None. If it is so, then search sys.modules for the module of
- global. */
+ /* In some rare cases (e.g., bound methods of extension types),
+ __module__ can be None. If it is so, then search sys.modules
+ for the module of global. */
 if (module_name == Py_None) {
 Py_DECREF(module_name);
 goto search;
@@ -4462,6 +4462,9 @@
 if (self->memo == NULL)
 return -1;
 
+ self->last_string = NULL;
+ self->arg = NULL;
+
 return 0;
 }
 
Deleted: python/branches/py3k-short-float-repr/Modules/_stringio.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/_stringio.c	Sun Apr 5 01:04:14 2009
+++ (empty file)
@@ -1,769 +0,0 @@
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "structmember.h"
-#include "_iomodule.h"
-
-/* Implementation note: the buffer is always at least one character longer
- than the enclosed string, for proper functioning of _PyIO_find_line_ending.
-*/
-
-typedef struct {
- PyObject_HEAD
- Py_UNICODE *buf;
- Py_ssize_t pos;
- Py_ssize_t string_size;
- size_t buf_size;
-
- char ok; /* initialized? */
- char closed;
- char readuniversal;
- char readtranslate;
- PyObject *decoder;
- PyObject *readnl;
- PyObject *writenl;
- 
- PyObject *dict;
- PyObject *weakreflist;
-} StringIOObject;
-
-#define CHECK_INITIALIZED(self) \
- if (self->ok <= 0) { \
- PyErr_SetString(PyExc_ValueError, \
- "I/O operation on uninitialized object"); \
- return NULL; \
- }
-
-#define CHECK_CLOSED(self) \
- if (self->closed) { \
- PyErr_SetString(PyExc_ValueError, \
- "I/O operation on closed file"); \
- return NULL; \
- }
-
-PyDoc_STRVAR(stringio_doc,
- "Text I/O implementation using an in-memory buffer.\n"
- "\n"
- "The initial_value argument sets the value of object. The newline\n"
- "argument is like the one of TextIOWrapper's constructor.");
-
-
-/* Internal routine for changing the size, in terms of characters, of the
- buffer of StringIO objects. The caller should ensure that the 'size'
- argument is non-negative. Returns 0 on success, -1 otherwise. */
-static int
-resize_buffer(StringIOObject *self, size_t size)
-{
- /* Here, unsigned types are used to avoid dealing with signed integer
- overflow, which is undefined in C. */
- size_t alloc = self->buf_size;
- Py_UNICODE *new_buf = NULL;
-
- assert(self->buf != NULL);
-
- /* Reserve one more char for line ending detection. */
- size = size + 1;
- /* For simplicity, stay in the range of the signed type. Anyway, Python
- doesn't allow strings to be longer than this. */
- if (size > PY_SSIZE_T_MAX)
- goto overflow;
-
- if (size < alloc / 2) {
- /* Major downsize; resize down to exact size. */
- alloc = size + 1;
- }
- else if (size < alloc) {
- /* Within allocated size; quick exit */
- return 0;
- }
- else if (size <= alloc * 1.125) {
- /* Moderate upsize; overallocate similar to list_resize() */
- alloc = size + (size >> 3) + (size < 9 ? 3 : 6);
- }
- else {
- /* Major upsize; resize up to exact size */
- alloc = size + 1;
- }
-
- if (alloc > ((size_t)-1) / sizeof(Py_UNICODE))
- goto overflow;
- new_buf = (Py_UNICODE *)PyMem_Realloc(self->buf,
- alloc * sizeof(Py_UNICODE));
- if (new_buf == NULL) {
- PyErr_NoMemory();
- return -1;
- }
- self->buf_size = alloc;
- self->buf = new_buf;
-
- return 0;
-
- overflow:
- PyErr_SetString(PyExc_OverflowError,
- "new buffer size too large");
- return -1;
-}
-
-/* Internal routine for writing a whole PyUnicode object to the buffer of a
- StringIO object. Returns 0 on success, or -1 on error. */
-static Py_ssize_t
-write_str(StringIOObject *self, PyObject *obj)
-{
- Py_UNICODE *str;
- Py_ssize_t len;
- PyObject *decoded = NULL;
- assert(self->buf != NULL);
- assert(self->pos >= 0);
-
- if (self->decoder != NULL) {
- decoded = _PyIncrementalNewlineDecoder_decode(
- self->decoder, obj, 1 /* always final */);
- }
- else {
- decoded = obj;
- Py_INCREF(decoded);
- }
- if (self->writenl) {
- PyObject *translated = PyUnicode_Replace(
- decoded, _PyIO_str_nl, self->writenl, -1);
- Py_DECREF(decoded);
- decoded = translated;
- }
- if (decoded == NULL)
- return -1;
-
- assert(PyUnicode_Check(decoded));
- str = PyUnicode_AS_UNICODE(decoded);
- len = PyUnicode_GET_SIZE(decoded);
-
- assert(len >= 0);
-
- /* This overflow check is not strictly necessary. However, it avoids us to
- deal with funky things like comparing an unsigned and a signed
- integer. */
- if (self->pos > PY_SSIZE_T_MAX - len) {
- PyErr_SetString(PyExc_OverflowError,
- "new position too large");
- goto fail;
- }
- if (self->pos + len > self->string_size) {
- if (resize_buffer(self, self->pos + len) < 0)
- goto fail;
- }
-
- if (self->pos > self->string_size) {
- /* In case of overseek, pad with null bytes the buffer region between
- the end of stream and the current position.
-
- 0 lo string_size hi
- | |<---used--->|<----------available----------->|
- | | <--to pad-->|<---to write---> |
- 0 buf positon
-
- */
- memset(self->buf + self->string_size, '0円',
- (self->pos - self->string_size) * sizeof(Py_UNICODE));
- }
-
- /* Copy the data to the internal buffer, overwriting some of the
- existing data if self->pos < self->string_size. */
- memcpy(self->buf + self->pos, str, len * sizeof(Py_UNICODE));
- self->pos += len;
-
- /* Set the new length of the internal string if it has changed. */
- if (self->string_size < self->pos) {
- self->string_size = self->pos;
- }
-
- Py_DECREF(decoded);
- return 0;
-
-fail:
- Py_XDECREF(decoded);
- return -1;
-}
-
-PyDoc_STRVAR(stringio_getvalue_doc,
- "Retrieve the entire contents of the object.");
-
-static PyObject *
-stringio_getvalue(StringIOObject *self)
-{
- CHECK_INITIALIZED(self);
- CHECK_CLOSED(self);
- return PyUnicode_FromUnicode(self->buf, self->string_size);
-}
-
-PyDoc_STRVAR(stringio_tell_doc,
- "Tell the current file position.");
-
-static PyObject *
-stringio_tell(StringIOObject *self)
-{
- CHECK_INITIALIZED(self);
- CHECK_CLOSED(self);
- return PyLong_FromSsize_t(self->pos);
-}
-
-PyDoc_STRVAR(stringio_read_doc,
- "Read at most n characters, returned as a string.\n"
- "\n"
- "If the argument is negative or omitted, read until EOF\n"
- "is reached. Return an empty string at EOF.\n");
-
-static PyObject *
-stringio_read(StringIOObject *self, PyObject *args)
-{
- Py_ssize_t size, n;
- Py_UNICODE *output;
- PyObject *arg = Py_None;
-
- CHECK_INITIALIZED(self);
- if (!PyArg_ParseTuple(args, "|O:read", &arg))
- return NULL;
- CHECK_CLOSED(self);
-
- if (PyNumber_Check(arg)) {
- size = PyNumber_AsSsize_t(arg, PyExc_OverflowError);
- if (size == -1 && PyErr_Occurred())
- return NULL;
- }
- else if (arg == Py_None) {
- /* Read until EOF is reached, by default. */
- size = -1;
- }
- else {
- PyErr_Format(PyExc_TypeError, "integer argument expected, got '%s'",
- Py_TYPE(arg)->tp_name);
- return NULL;
- }
-
- /* adjust invalid sizes */
- n = self->string_size - self->pos;
- if (size < 0 || size > n) {
- size = n;
- if (size < 0)
- size = 0;
- }
-
- output = self->buf + self->pos;
- self->pos += size;
- return PyUnicode_FromUnicode(output, size);
-}
-
-/* Internal helper, used by stringio_readline and stringio_iternext */
-static PyObject *
-_stringio_readline(StringIOObject *self, Py_ssize_t limit)
-{
- Py_UNICODE *start, *end, old_char;
- Py_ssize_t len, consumed;
-
- /* In case of overseek, return the empty string */
- if (self->pos >= self->string_size)
- return PyUnicode_FromString("");
-
- start = self->buf + self->pos;
- if (limit < 0 || limit > self->string_size - self->pos)
- limit = self->string_size - self->pos;
-
- end = start + limit;
- old_char = *end;
- *end = '0円';
- len = _PyIO_find_line_ending(
- self->readtranslate, self->readuniversal, self->readnl,
- start, end, &consumed);
- *end = old_char;
- /* If we haven't found any line ending, we just return everything
- (`consumed` is ignored). */
- if (len < 0)
- len = limit;
- self->pos += len;
- return PyUnicode_FromUnicode(start, len);
-}
-
-PyDoc_STRVAR(stringio_readline_doc,
- "Read until newline or EOF.\n"
- "\n"
- "Returns an empty string if EOF is hit immediately.\n");
-
-static PyObject *
-stringio_readline(StringIOObject *self, PyObject *args)
-{
- PyObject *arg = Py_None;
- Py_ssize_t limit = -1;
-
- CHECK_INITIALIZED(self);
- if (!PyArg_ParseTuple(args, "|O:readline", &arg))
- return NULL;
- CHECK_CLOSED(self);
-
- if (PyNumber_Check(arg)) {
- limit = PyNumber_AsSsize_t(arg, PyExc_OverflowError);
- if (limit == -1 && PyErr_Occurred())
- return NULL;
- }
- else if (arg != Py_None) {
- PyErr_Format(PyExc_TypeError, "integer argument expected, got '%s'",
- Py_TYPE(arg)->tp_name);
- return NULL;
- }
- return _stringio_readline(self, limit);
-}
-
-static PyObject *
-stringio_iternext(StringIOObject *self)
-{
- PyObject *line;
-
- CHECK_INITIALIZED(self);
- CHECK_CLOSED(self);
-
- if (Py_TYPE(self) == &PyStringIO_Type) {
- /* Skip method call overhead for speed */
- line = _stringio_readline(self, -1);
- }
- else {
- /* XXX is subclassing StringIO really supported? */
- line = PyObject_CallMethodObjArgs((PyObject *)self,
- _PyIO_str_readline, NULL);
- if (line && !PyUnicode_Check(line)) {
- PyErr_Format(PyExc_IOError,
- "readline() should have returned an str object, "
- "not '%.200s'", Py_TYPE(line)->tp_name);
- Py_DECREF(line);
- return NULL;
- }
- }
-
- if (line == NULL)
- return NULL;
-
- if (PyUnicode_GET_SIZE(line) == 0) {
- /* Reached EOF */
- Py_DECREF(line);
- return NULL;
- }
-
- return line;
-}
-
-PyDoc_STRVAR(stringio_truncate_doc,
- "Truncate size to pos.\n"
- "\n"
- "The pos argument defaults to the current file position, as\n"
- "returned by tell(). Imply an absolute seek to pos.\n"
- "Returns the new absolute position.\n");
-
-static PyObject *
-stringio_truncate(StringIOObject *self, PyObject *args)
-{
- Py_ssize_t size;
- PyObject *arg = Py_None;
-
- CHECK_INITIALIZED(self);
- if (!PyArg_ParseTuple(args, "|O:truncate", &arg))
- return NULL;
- CHECK_CLOSED(self);
-
- if (PyNumber_Check(arg)) {
- size = PyNumber_AsSsize_t(arg, PyExc_OverflowError);
- if (size == -1 && PyErr_Occurred())
- return NULL;
- }
- else if (arg == Py_None) {
- /* Truncate to current position if no argument is passed. */
- size = self->pos;
- }
- else {
- PyErr_Format(PyExc_TypeError, "integer argument expected, got '%s'",
- Py_TYPE(arg)->tp_name);
- return NULL;
- }
-
- if (size < 0) {
- PyErr_Format(PyExc_ValueError,
- "Negative size value %zd", size);
- return NULL;
- }
-
- if (size < self->string_size) {
- if (resize_buffer(self, size) < 0)
- return NULL;
- self->string_size = size;
- }
- self->pos = size;
-
- return PyLong_FromSsize_t(size);
-}
-
-PyDoc_STRVAR(stringio_seek_doc,
- "Change stream position.\n"
- "\n"
- "Seek to character offset pos relative to position indicated by whence:\n"
- " 0 Start of stream (the default). pos should be >= 0;\n"
- " 1 Current position - pos must be 0;\n"
- " 2 End of stream - pos must be 0.\n"
- "Returns the new absolute position.\n");
-
-static PyObject *
-stringio_seek(StringIOObject *self, PyObject *args)
-{
- Py_ssize_t pos;
- int mode = 0;
-
- CHECK_INITIALIZED(self);
- if (!PyArg_ParseTuple(args, "n|i:seek", &pos, &mode))
- return NULL;
- CHECK_CLOSED(self);
-
- if (mode != 0 && mode != 1 && mode != 2) {
- PyErr_Format(PyExc_ValueError,
- "Invalid whence (%i, should be 0, 1 or 2)", mode);
- return NULL;
- }
- else if (pos < 0 && mode == 0) {
- PyErr_Format(PyExc_ValueError,
- "Negative seek position %zd", pos);
- return NULL;
- }
- else if (mode != 0 && pos != 0) {
- PyErr_SetString(PyExc_IOError,
- "Can't do nonzero cur-relative seeks");
- return NULL;
- }
-
- /* mode 0: offset relative to beginning of the string.
- mode 1: no change to current position.
- mode 2: change position to end of file. */
- if (mode == 1) {
- pos = self->pos;
- }
- else if (mode == 2) {
- pos = self->string_size;
- }
-
- self->pos = pos;
-
- return PyLong_FromSsize_t(self->pos);
-}
-
-PyDoc_STRVAR(stringio_write_doc,
- "Write string to file.\n"
- "\n"
- "Returns the number of characters written, which is always equal to\n"
- "the length of the string.\n");
-
-static PyObject *
-stringio_write(StringIOObject *self, PyObject *obj)
-{
- Py_ssize_t size;
-
- CHECK_INITIALIZED(self);
- if (!PyUnicode_Check(obj)) {
- PyErr_Format(PyExc_TypeError, "string argument expected, got '%s'",
- Py_TYPE(obj)->tp_name);
- return NULL;
- }
- CHECK_CLOSED(self);
- size = PyUnicode_GET_SIZE(obj);
-
- if (size > 0 && write_str(self, obj) < 0)
- return NULL;
-
- return PyLong_FromSsize_t(size);
-}
-
-PyDoc_STRVAR(stringio_close_doc,
- "Close the IO object. Attempting any further operation after the\n"
- "object is closed will raise a ValueError.\n"
- "\n"
- "This method has no effect if the file is already closed.\n");
-
-static PyObject *
-stringio_close(StringIOObject *self)
-{
- self->closed = 1;
- /* Free up some memory */
- if (resize_buffer(self, 0) < 0)
- return NULL;
- Py_CLEAR(self->readnl);
- Py_CLEAR(self->writenl);
- Py_CLEAR(self->decoder);
- Py_RETURN_NONE;
-}
-
-static int
-stringio_traverse(StringIOObject *self, visitproc visit, void *arg)
-{
- Py_VISIT(self->dict);
- return 0;
-}
-
-static int
-stringio_clear(StringIOObject *self)
-{
- Py_CLEAR(self->dict);
- return 0;
-}
-
-static void
-stringio_dealloc(StringIOObject *self)
-{
- _PyObject_GC_UNTRACK(self);
- Py_CLEAR(self->readnl);
- Py_CLEAR(self->writenl);
- Py_CLEAR(self->decoder);
- if (self->buf)
- PyMem_Free(self->buf);
- if (self->weakreflist != NULL)
- PyObject_ClearWeakRefs((PyObject *) self);
- Py_TYPE(self)->tp_free(self);
-}
-
-static PyObject *
-stringio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- StringIOObject *self;
-
- assert(type != NULL && type->tp_alloc != NULL);
- self = (StringIOObject *)type->tp_alloc(type, 0);
- if (self == NULL)
- return NULL;
-
- self->string_size = 0;
- self->pos = 0;
- self->buf_size = 0;
- self->buf = (Py_UNICODE *)PyMem_Malloc(0);
- if (self->buf == NULL) {
- Py_DECREF(self);
- return PyErr_NoMemory();
- }
-
- return (PyObject *)self;
-}
-
-static int
-stringio_init(StringIOObject *self, PyObject *args, PyObject *kwds)
-{
- char *kwlist[] = {"initial_value", "newline", NULL};
- PyObject *value = NULL;
- char *newline = "\n";
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oz:__init__", kwlist,
- &value, &newline))
- return -1;
-
- if (newline && newline[0] != '0円'
- && !(newline[0] == '\n' && newline[1] == '0円')
- && !(newline[0] == '\r' && newline[1] == '0円')
- && !(newline[0] == '\r' && newline[1] == '\n' && newline[2] == '0円')) {
- PyErr_Format(PyExc_ValueError,
- "illegal newline value: %s", newline);
- return -1;
- }
- if (value && value != Py_None && !PyUnicode_Check(value)) {
- PyErr_Format(PyExc_ValueError,
- "initial_value must be str or None, not %.200s",
- Py_TYPE(value)->tp_name);
- return -1;
- }
-
- self->ok = 0;
-
- Py_CLEAR(self->readnl);
- Py_CLEAR(self->writenl);
- Py_CLEAR(self->decoder);
-
- if (newline) {
- self->readnl = PyUnicode_FromString(newline);
- if (self->readnl == NULL)
- return -1;
- }
- self->readuniversal = (newline == NULL || newline[0] == '0円');
- self->readtranslate = (newline == NULL);
- /* If newline == "", we don't translate anything.
- If newline == "\n" or newline == None, we translate to "\n", which is
- a no-op.
- (for newline == None, TextIOWrapper translates to os.sepline, but it
- is pointless for StringIO)
- */
- if (newline != NULL && newline[0] == '\r') {
- self->writenl = self->readnl;
- Py_INCREF(self->writenl);
- }
-
- if (self->readuniversal) {
- self->decoder = PyObject_CallFunction(
- (PyObject *)&PyIncrementalNewlineDecoder_Type,
- "Oi", Py_None, (int) self->readtranslate);
- if (self->decoder == NULL)
- return -1;
- }
-
- /* Now everything is set up, resize buffer to size of initial value,
- and copy it */
- self->string_size = 0;
- if (value && value != Py_None) {
- Py_ssize_t len = PyUnicode_GetSize(value);
- /* This is a heuristic, for newline translation might change
- the string length. */
- if (resize_buffer(self, len) < 0)
- return -1;
- self->pos = 0;
- if (write_str(self, value) < 0)
- return -1;
- }
- else {
- if (resize_buffer(self, 0) < 0)
- return -1;
- }
- self->pos = 0;
-
- self->closed = 0;
- self->ok = 1;
- return 0;
-}
-
-/* Properties and pseudo-properties */
-static PyObject *
-stringio_seekable(StringIOObject *self, PyObject *args)
-{
- CHECK_INITIALIZED(self);
- Py_RETURN_TRUE;
-}
-
-static PyObject *
-stringio_readable(StringIOObject *self, PyObject *args)
-{
- CHECK_INITIALIZED(self);
- Py_RETURN_TRUE;
-}
-
-static PyObject *
-stringio_writable(StringIOObject *self, PyObject *args)
-{
- CHECK_INITIALIZED(self);
- Py_RETURN_TRUE;
-}
-
-static PyObject *
-stringio_buffer(StringIOObject *self, void *context)
-{
- PyErr_SetString(IO_STATE->unsupported_operation,
- "buffer attribute is unsupported on type StringIO");
- return NULL;
-}
-
-static PyObject *
-stringio_closed(StringIOObject *self, void *context)
-{
- CHECK_INITIALIZED(self);
- return PyBool_FromLong(self->closed);
-}
-
-static PyObject *
-stringio_encoding(StringIOObject *self, void *context)
-{
- CHECK_INITIALIZED(self);
- CHECK_CLOSED(self);
- Py_RETURN_NONE;
-}
-
-static PyObject *
-stringio_errors(StringIOObject *self, void *context)
-{
- CHECK_INITIALIZED(self);
- CHECK_CLOSED(self);
- return PyUnicode_FromString("strict");
-}
-
-static PyObject *
-stringio_line_buffering(StringIOObject *self, void *context)
-{
- CHECK_INITIALIZED(self);
- CHECK_CLOSED(self);
- Py_RETURN_FALSE;
-}
-
-static PyObject *
-stringio_newlines(StringIOObject *self, void *context)
-{
- CHECK_INITIALIZED(self);
- CHECK_CLOSED(self);
- if (self->decoder == NULL)
- Py_RETURN_NONE;
- return PyObject_GetAttr(self->decoder, _PyIO_str_newlines);
-}
-
-static struct PyMethodDef stringio_methods[] = {
- {"close", (PyCFunction)stringio_close, METH_NOARGS, stringio_close_doc},
- {"getvalue", (PyCFunction)stringio_getvalue, METH_VARARGS, stringio_getvalue_doc},
- {"read", (PyCFunction)stringio_read, METH_VARARGS, stringio_read_doc},
- {"readline", (PyCFunction)stringio_readline, METH_VARARGS, stringio_readline_doc},
- {"tell", (PyCFunction)stringio_tell, METH_NOARGS, stringio_tell_doc},
- {"truncate", (PyCFunction)stringio_truncate, METH_VARARGS, stringio_truncate_doc},
- {"seek", (PyCFunction)stringio_seek, METH_VARARGS, stringio_seek_doc},
- {"write", (PyCFunction)stringio_write, METH_O, stringio_write_doc},
- 
- {"seekable", (PyCFunction)stringio_seekable, METH_NOARGS},
- {"readable", (PyCFunction)stringio_readable, METH_NOARGS},
- {"writable", (PyCFunction)stringio_writable, METH_NOARGS},
- {NULL, NULL} /* sentinel */
-};
-
-static PyGetSetDef stringio_getset[] = {
- {"closed", (getter)stringio_closed, NULL, NULL},
- {"newlines", (getter)stringio_newlines, NULL, NULL},
- /* (following comments straight off of the original Python wrapper:)
- XXX Cruft to support the TextIOWrapper API. This would only
- be meaningful if StringIO supported the buffer attribute.
- Hopefully, a better solution, than adding these pseudo-attributes,
- will be found.
- */
- {"buffer", (getter)stringio_buffer, NULL, NULL},
- {"encoding", (getter)stringio_encoding, NULL, NULL},
- {"errors", (getter)stringio_errors, NULL, NULL},
- {"line_buffering", (getter)stringio_line_buffering, NULL, NULL},
- {0}
-};
-
-PyTypeObject PyStringIO_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "_io.StringIO", /*tp_name*/
- sizeof(StringIOObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)stringio_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_reserved*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash*/
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
- | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
- stringio_doc, /*tp_doc*/
- (traverseproc)stringio_traverse, /*tp_traverse*/
- (inquiry)stringio_clear, /*tp_clear*/
- 0, /*tp_richcompare*/
- offsetof(StringIOObject, weakreflist), /*tp_weaklistoffset*/
- 0, /*tp_iter*/
- (iternextfunc)stringio_iternext, /*tp_iternext*/
- stringio_methods, /*tp_methods*/
- 0, /*tp_members*/
- stringio_getset, /*tp_getset*/
- 0, /*tp_base*/
- 0, /*tp_dict*/
- 0, /*tp_descr_get*/
- 0, /*tp_descr_set*/
- offsetof(StringIOObject, dict), /*tp_dictoffset*/
- (initproc)stringio_init, /*tp_init*/
- 0, /*tp_alloc*/
- stringio_new, /*tp_new*/
-};
Deleted: python/branches/py3k-short-float-repr/Modules/_textio.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/_textio.c	Sun Apr 5 01:04:14 2009
+++ (empty file)
@@ -1,2415 +0,0 @@
-/*
- An implementation of Text I/O as defined by PEP 3116 - "New I/O"
-
- Classes defined here: TextIOBase, IncrementalNewlineDecoder, TextIOWrapper.
-
- Written by Amaury Forgeot d'Arc and Antoine Pitrou
-*/
-
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "structmember.h"
-#include "_iomodule.h"
-
-/* TextIOBase */
-
-PyDoc_STRVAR(TextIOBase_doc,
- "Base class for text I/O.\n"
- "\n"
- "This class provides a character and line based interface to stream\n"
- "I/O. There is no readinto method because Python's character strings\n"
- "are immutable. There is no public constructor.\n"
- );
-
-static PyObject *
-_unsupported(const char *message)
-{
- PyErr_SetString(IO_STATE->unsupported_operation, message);
- return NULL;
-}
-
-PyDoc_STRVAR(TextIOBase_read_doc,
- "Read at most n characters from stream.\n"
- "\n"
- "Read from underlying buffer until we have n characters or we hit EOF.\n"
- "If n is negative or omitted, read until EOF.\n"
- );
-
-static PyObject *
-TextIOBase_read(PyObject *self, PyObject *args)
-{
- return _unsupported("read");
-}
-
-PyDoc_STRVAR(TextIOBase_readline_doc,
- "Read until newline or EOF.\n"
- "\n"
- "Returns an empty string if EOF is hit immediately.\n"
- );
-
-static PyObject *
-TextIOBase_readline(PyObject *self, PyObject *args)
-{
- return _unsupported("readline");
-}
-
-PyDoc_STRVAR(TextIOBase_write_doc,
- "Write string to stream.\n"
- "Returns the number of characters written (which is always equal to\n"
- "the length of the string).\n"
- );
-
-static PyObject *
-TextIOBase_write(PyObject *self, PyObject *args)
-{
- return _unsupported("write");
-}
-
-PyDoc_STRVAR(TextIOBase_encoding_doc,
- "Encoding of the text stream.\n"
- "\n"
- "Subclasses should override.\n"
- );
-
-static PyObject *
-TextIOBase_encoding_get(PyObject *self, void *context)
-{
- Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(TextIOBase_newlines_doc,
- "Line endings translated so far.\n"
- "\n"
- "Only line endings translated during reading are considered.\n"
- "\n"
- "Subclasses should override.\n"
- );
-
-static PyObject *
-TextIOBase_newlines_get(PyObject *self, void *context)
-{
- Py_RETURN_NONE;
-}
-
-
-static PyMethodDef TextIOBase_methods[] = {
- {"read", TextIOBase_read, METH_VARARGS, TextIOBase_read_doc},
- {"readline", TextIOBase_readline, METH_VARARGS, TextIOBase_readline_doc},
- {"write", TextIOBase_write, METH_VARARGS, TextIOBase_write_doc},
- {NULL, NULL}
-};
-
-static PyGetSetDef TextIOBase_getset[] = {
- {"encoding", (getter)TextIOBase_encoding_get, NULL, TextIOBase_encoding_doc},
- {"newlines", (getter)TextIOBase_newlines_get, NULL, TextIOBase_newlines_doc},
- {0}
-};
-
-PyTypeObject PyTextIOBase_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "_io._TextIOBase", /*tp_name*/
- 0, /*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, /*tp_flags*/
- TextIOBase_doc, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- TextIOBase_methods, /* tp_methods */
- 0, /* tp_members */
- TextIOBase_getset, /* tp_getset */
- &PyIOBase_Type, /* 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 */
-};
-
-
-/* IncrementalNewlineDecoder */
-
-PyDoc_STRVAR(IncrementalNewlineDecoder_doc,
- "Codec used when reading a file in universal newlines mode. It wraps\n"
- "another incremental decoder, translating \\r\\n and \\r into \\n. It also\n"
- "records the types of newlines encountered. When used with\n"
- "translate=False, it ensures that the newline sequence is returned in\n"
- "one piece. When used with decoder=None, it expects unicode strings as\n"
- "decode input and translates newlines without first invoking an external\n"
- "decoder.\n"
- );
-
-typedef struct {
- PyObject_HEAD
- PyObject *decoder;
- PyObject *errors;
- int pendingcr:1;
- int translate:1;
- unsigned int seennl:3;
-} PyNewLineDecoderObject;
-
-static int
-IncrementalNewlineDecoder_init(PyNewLineDecoderObject *self,
- PyObject *args, PyObject *kwds)
-{
- PyObject *decoder;
- int translate;
- PyObject *errors = NULL;
- char *kwlist[] = {"decoder", "translate", "errors", NULL};
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "Oi|O:IncrementalNewlineDecoder",
- kwlist, &decoder, &translate, &errors))
- return -1;
-
- self->decoder = decoder;
- Py_INCREF(decoder);
-
- if (errors == NULL) {
- self->errors = PyUnicode_FromString("strict");
- if (self->errors == NULL)
- return -1;
- }
- else {
- Py_INCREF(errors);
- self->errors = errors;
- }
-
- self->translate = translate;
- self->seennl = 0;
- self->pendingcr = 0;
-
- return 0;
-}
-
-static void
-IncrementalNewlineDecoder_dealloc(PyNewLineDecoderObject *self)
-{
- Py_CLEAR(self->decoder);
- Py_CLEAR(self->errors);
- Py_TYPE(self)->tp_free((PyObject *)self);
-}
-
-#define SEEN_CR 1
-#define SEEN_LF 2
-#define SEEN_CRLF 4
-#define SEEN_ALL (SEEN_CR | SEEN_LF | SEEN_CRLF)
-
-PyObject *
-_PyIncrementalNewlineDecoder_decode(PyObject *_self,
- PyObject *input, int final)
-{
- PyObject *output;
- Py_ssize_t output_len;
- PyNewLineDecoderObject *self = (PyNewLineDecoderObject *) _self;
-
- if (self->decoder == NULL) {
- PyErr_SetString(PyExc_ValueError,
- "IncrementalNewlineDecoder.__init__ not called");
- return NULL;
- }
-
- /* decode input (with the eventual \r from a previous pass) */
- if (self->decoder != Py_None) {
- output = PyObject_CallMethodObjArgs(self->decoder,
- _PyIO_str_decode, input, final ? Py_True : Py_False, NULL);
- }
- else {
- output = input;
- Py_INCREF(output);
- }
-
- if (output == NULL)
- return NULL;
-
- if (!PyUnicode_Check(output)) {
- PyErr_SetString(PyExc_TypeError,
- "decoder should return a string result");
- goto error;
- }
-
- output_len = PyUnicode_GET_SIZE(output);
- if (self->pendingcr && (final || output_len > 0)) {
- Py_UNICODE *out;
- PyObject *modified = PyUnicode_FromUnicode(NULL, output_len + 1);
- if (modified == NULL)
- goto error;
- out = PyUnicode_AS_UNICODE(modified);
- out[0] = '\r';
- memcpy(out + 1, PyUnicode_AS_UNICODE(output),
- output_len * sizeof(Py_UNICODE));
- Py_DECREF(output);
- output = modified;
- self->pendingcr = 0;
- output_len++;
- }
-
- /* retain last \r even when not translating data:
- * then readline() is sure to get \r\n in one pass
- */
- if (!final) {
- if (output_len > 0
- && PyUnicode_AS_UNICODE(output)[output_len - 1] == '\r') {
-
- if (Py_REFCNT(output) == 1) {
- if (PyUnicode_Resize(&output, output_len - 1) < 0)
- goto error;
- }
- else {
- PyObject *modified = PyUnicode_FromUnicode(
- PyUnicode_AS_UNICODE(output),
- output_len - 1);
- if (modified == NULL)
- goto error;
- Py_DECREF(output);
- output = modified;
- }
- self->pendingcr = 1;
- }
- }
-
- /* Record which newlines are read and do newline translation if desired,
- all in one pass. */
- {
- Py_UNICODE *in_str;
- Py_ssize_t len;
- int seennl = self->seennl;
- int only_lf = 0;
-
- in_str = PyUnicode_AS_UNICODE(output);
- len = PyUnicode_GET_SIZE(output);
-
- if (len == 0)
- return output;
-
- /* If, up to now, newlines are consistently \n, do a quick check
- for the \r *byte* with the libc's optimized memchr.
- */
- if (seennl == SEEN_LF || seennl == 0) {
- only_lf = (memchr(in_str, '\r', len * sizeof(Py_UNICODE)) == NULL);
- }
-
- if (only_lf) {
- /* If not already seen, quick scan for a possible "\n" character.
- (there's nothing else to be done, even when in translation mode)
- */
- if (seennl == 0 &&
- memchr(in_str, '\n', len * sizeof(Py_UNICODE)) != NULL) {
- Py_UNICODE *s, *end;
- s = in_str;
- end = in_str + len;
- for (;;) {
- Py_UNICODE c;
- /* Fast loop for non-control characters */
- while (*s > '\n')
- s++;
- c = *s++;
- if (c == '\n') {
- seennl |= SEEN_LF;
- break;
- }
- if (s > end)
- break;
- }
- }
- /* Finished: we have scanned for newlines, and none of them
- need translating */
- }
- else if (!self->translate) {
- Py_UNICODE *s, *end;
- /* We have already seen all newline types, no need to scan again */
- if (seennl == SEEN_ALL)
- goto endscan;
- s = in_str;
- end = in_str + len;
- for (;;) {
- Py_UNICODE c;
- /* Fast loop for non-control characters */
- while (*s > '\r')
- s++;
- c = *s++;
- if (c == '\n')
- seennl |= SEEN_LF;
- else if (c == '\r') {
- if (*s == '\n') {
- seennl |= SEEN_CRLF;
- s++;
- }
- else
- seennl |= SEEN_CR;
- }
- if (s > end)
- break;
- if (seennl == SEEN_ALL)
- break;
- }
- endscan:
- ;
- }
- else {
- PyObject *translated = NULL;
- Py_UNICODE *out_str;
- Py_UNICODE *in, *out, *end;
- if (Py_REFCNT(output) != 1) {
- /* We could try to optimize this so that we only do a copy
- when there is something to translate. On the other hand,
- most decoders should only output non-shared strings, i.e.
- translation is done in place. */
- translated = PyUnicode_FromUnicode(NULL, len);
- if (translated == NULL)
- goto error;
- assert(Py_REFCNT(translated) == 1);
- memcpy(PyUnicode_AS_UNICODE(translated),
- PyUnicode_AS_UNICODE(output),
- len * sizeof(Py_UNICODE));
- }
- else {
- translated = output;
- }
- out_str = PyUnicode_AS_UNICODE(translated);
- in = in_str;
- out = out_str;
- end = in_str + len;
- for (;;) {
- Py_UNICODE c;
- /* Fast loop for non-control characters */
- while ((c = *in++) > '\r')
- *out++ = c;
- if (c == '\n') {
- *out++ = c;
- seennl |= SEEN_LF;
- continue;
- }
- if (c == '\r') {
- if (*in == '\n') {
- in++;
- seennl |= SEEN_CRLF;
- }
- else
- seennl |= SEEN_CR;
- *out++ = '\n';
- continue;
- }
- if (in > end)
- break;
- *out++ = c;
- }
- if (translated != output) {
- Py_DECREF(output);
- output = translated;
- }
- if (out - out_str != len) {
- if (PyUnicode_Resize(&output, out - out_str) < 0)
- goto error;
- }
- }
- self->seennl |= seennl;
- }
-
- return output;
-
- error:
- Py_DECREF(output);
- return NULL;
-}
-
-static PyObject *
-IncrementalNewlineDecoder_decode(PyNewLineDecoderObject *self,
- PyObject *args, PyObject *kwds)
-{
- char *kwlist[] = {"input", "final", NULL};
- PyObject *input;
- int final = 0;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|i:IncrementalNewlineDecoder",
- kwlist, &input, &final))
- return NULL;
- return _PyIncrementalNewlineDecoder_decode((PyObject *) self, input, final);
-}
-
-static PyObject *
-IncrementalNewlineDecoder_getstate(PyNewLineDecoderObject *self, PyObject *args)
-{
- PyObject *buffer;
- unsigned PY_LONG_LONG flag;
-
- if (self->decoder != Py_None) {
- PyObject *state = PyObject_CallMethodObjArgs(self->decoder,
- _PyIO_str_getstate, NULL);
- if (state == NULL)
- return NULL;
- if (!PyArg_Parse(state, "(OK)", &buffer, &flag)) {
- Py_DECREF(state);
- return NULL;
- }
- Py_INCREF(buffer);
- Py_DECREF(state);
- }
- else {
- buffer = PyBytes_FromString("");
- flag = 0;
- }
- flag <<= 1;
- if (self->pendingcr)
- flag |= 1;
- return Py_BuildValue("NK", buffer, flag);
-}
-
-static PyObject *
-IncrementalNewlineDecoder_setstate(PyNewLineDecoderObject *self, PyObject *state)
-{
- PyObject *buffer;
- unsigned PY_LONG_LONG flag;
-
- if (!PyArg_Parse(state, "(OK)", &buffer, &flag))
- return NULL;
-
- self->pendingcr = (int) flag & 1;
- flag >>= 1;
-
- if (self->decoder != Py_None)
- return PyObject_CallMethod(self->decoder,
- "setstate", "((OK))", buffer, flag);
- else
- Py_RETURN_NONE;
-}
-
-static PyObject *
-IncrementalNewlineDecoder_reset(PyNewLineDecoderObject *self, PyObject *args)
-{
- self->seennl = 0;
- self->pendingcr = 0;
- if (self->decoder != Py_None)
- return PyObject_CallMethodObjArgs(self->decoder, _PyIO_str_reset, NULL);
- else
- Py_RETURN_NONE;
-}
-
-static PyObject *
-IncrementalNewlineDecoder_newlines_get(PyNewLineDecoderObject *self, void *context)
-{
- switch (self->seennl) {
- case SEEN_CR:
- return PyUnicode_FromString("\r");
- case SEEN_LF:
- return PyUnicode_FromString("\n");
- case SEEN_CRLF:
- return PyUnicode_FromString("\r\n");
- case SEEN_CR | SEEN_LF:
- return Py_BuildValue("ss", "\r", "\n");
- case SEEN_CR | SEEN_CRLF:
- return Py_BuildValue("ss", "\r", "\r\n");
- case SEEN_LF | SEEN_CRLF:
- return Py_BuildValue("ss", "\n", "\r\n");
- case SEEN_CR | SEEN_LF | SEEN_CRLF:
- return Py_BuildValue("sss", "\r", "\n", "\r\n");
- default:
- Py_RETURN_NONE;
- }
-
-}
-
-
-static PyMethodDef IncrementalNewlineDecoder_methods[] = {
- {"decode", (PyCFunction)IncrementalNewlineDecoder_decode, METH_VARARGS|METH_KEYWORDS},
- {"getstate", (PyCFunction)IncrementalNewlineDecoder_getstate, METH_NOARGS},
- {"setstate", (PyCFunction)IncrementalNewlineDecoder_setstate, METH_O},
- {"reset", (PyCFunction)IncrementalNewlineDecoder_reset, METH_NOARGS},
- {0}
-};
-
-static PyGetSetDef IncrementalNewlineDecoder_getset[] = {
- {"newlines", (getter)IncrementalNewlineDecoder_newlines_get, NULL, NULL},
- {0}
-};
-
-PyTypeObject PyIncrementalNewlineDecoder_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "_io.IncrementalNewlineDecoder", /*tp_name*/
- sizeof(PyNewLineDecoderObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)IncrementalNewlineDecoder_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 | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- IncrementalNewlineDecoder_doc, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /*tp_weaklistoffset*/
- 0, /* tp_iter */
- 0, /* tp_iternext */
- IncrementalNewlineDecoder_methods, /* tp_methods */
- 0, /* tp_members */
- IncrementalNewlineDecoder_getset, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)IncrementalNewlineDecoder_init, /* tp_init */
- 0, /* tp_alloc */
- PyType_GenericNew, /* tp_new */
-};
-
-
-/* TextIOWrapper */
-
-PyDoc_STRVAR(TextIOWrapper_doc,
- "Character and line based layer over a BufferedIOBase object, buffer.\n"
- "\n"
- "encoding gives the name of the encoding that the stream will be\n"
- "decoded or encoded with. It defaults to locale.getpreferredencoding.\n"
- "\n"
- "errors determines the strictness of encoding and decoding (see the\n"
- "codecs.register) and defaults to \"strict\".\n"
- "\n"
- "newline can be None, '', '\\n', '\\r', or '\\r\\n'. It controls the\n"
- "handling of line endings. If it is None, universal newlines is\n"
- "enabled. With this enabled, on input, the lines endings '\\n', '\\r',\n"
- "or '\\r\\n' are translated to '\\n' before being returned to the\n"
- "caller. Conversely, on output, '\\n' is translated to the system\n"
- "default line seperator, os.linesep. If newline is any other of its\n"
- "legal values, that newline becomes the newline when the file is read\n"
- "and it is returned untranslated. On output, '\\n' is converted to the\n"
- "newline.\n"
- "\n"
- "If line_buffering is True, a call to flush is implied when a call to\n"
- "write contains a newline character."
- );
-
-typedef PyObject *
- (*encodefunc_t)(PyObject *, PyObject *);
-
-typedef struct
-{
- PyObject_HEAD
- int ok; /* initialized? */
- Py_ssize_t chunk_size;
- PyObject *buffer;
- PyObject *encoding;
- PyObject *encoder;
- PyObject *decoder;
- PyObject *readnl;
- PyObject *errors;
- const char *writenl; /* utf-8 encoded, NULL stands for \n */
- char line_buffering;
- char readuniversal;
- char readtranslate;
- char writetranslate;
- char seekable;
- char telling;
- /* Specialized encoding func (see below) */
- encodefunc_t encodefunc;
-
- /* Reads and writes are internally buffered in order to speed things up.
- However, any read will first flush the write buffer if itsn't empty.
-
- Please also note that text to be written is first encoded before being
- buffered. This is necessary so that encoding errors are immediately
- reported to the caller, but it unfortunately means that the
- IncrementalEncoder (whose encode() method is always written in Python)
- becomes a bottleneck for small writes.
- */
- PyObject *decoded_chars; /* buffer for text returned from decoder */
- Py_ssize_t decoded_chars_used; /* offset into _decoded_chars for read() */
- PyObject *pending_bytes; /* list of bytes objects waiting to be
- written, or NULL */
- Py_ssize_t pending_bytes_count;
- PyObject *snapshot;
- /* 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().
- */
-
- /* Cache raw object if it's a FileIO object */
- PyObject *raw;
-
- PyObject *weakreflist;
- PyObject *dict;
-} PyTextIOWrapperObject;
-
-
-/* A couple of specialized cases in order to bypass the slow incremental
- encoding methods for the most popular encodings. */
-
-static PyObject *
-ascii_encode(PyTextIOWrapperObject *self, PyObject *text)
-{
- return PyUnicode_EncodeASCII(PyUnicode_AS_UNICODE(text),
- PyUnicode_GET_SIZE(text),
- PyBytes_AS_STRING(self->errors));
-}
-
-static PyObject *
-utf16be_encode(PyTextIOWrapperObject *self, PyObject *text)
-{
- return PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(text),
- PyUnicode_GET_SIZE(text),
- PyBytes_AS_STRING(self->errors), 1);
-}
-
-static PyObject *
-utf16le_encode(PyTextIOWrapperObject *self, PyObject *text)
-{
- return PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(text),
- PyUnicode_GET_SIZE(text),
- PyBytes_AS_STRING(self->errors), -1);
-}
-
-static PyObject *
-utf16_encode(PyTextIOWrapperObject *self, PyObject *text)
-{
- PyObject *res;
- res = PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(text),
- PyUnicode_GET_SIZE(text),
- PyBytes_AS_STRING(self->errors), 0);
- if (res == NULL)
- return NULL;
- /* Next writes will skip the BOM and use native byte ordering */
-#if defined(WORDS_BIGENDIAN)
- self->encodefunc = (encodefunc_t) utf16be_encode;
-#else
- self->encodefunc = (encodefunc_t) utf16le_encode;
-#endif
- return res;
-}
-
-
-static PyObject *
-utf8_encode(PyTextIOWrapperObject *self, PyObject *text)
-{
- return PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(text),
- PyUnicode_GET_SIZE(text),
- PyBytes_AS_STRING(self->errors));
-}
-
-static PyObject *
-latin1_encode(PyTextIOWrapperObject *self, PyObject *text)
-{
- return PyUnicode_EncodeLatin1(PyUnicode_AS_UNICODE(text),
- PyUnicode_GET_SIZE(text),
- PyBytes_AS_STRING(self->errors));
-}
-
-/* Map normalized encoding names onto the specialized encoding funcs */
-
-typedef struct {
- const char *name;
- encodefunc_t encodefunc;
-} encodefuncentry;
-
-static encodefuncentry encodefuncs[] = {
- {"ascii", (encodefunc_t) ascii_encode},
- {"iso8859-1", (encodefunc_t) latin1_encode},
- {"utf-16-be", (encodefunc_t) utf16be_encode},
- {"utf-16-le", (encodefunc_t) utf16le_encode},
- {"utf-16", (encodefunc_t) utf16_encode},
- {"utf-8", (encodefunc_t) utf8_encode},
- {NULL, NULL}
-};
-
-
-static int
-TextIOWrapper_init(PyTextIOWrapperObject *self, PyObject *args, PyObject *kwds)
-{
- char *kwlist[] = {"buffer", "encoding", "errors",
- "newline", "line_buffering",
- NULL};
- PyObject *buffer, *raw;
- char *encoding = NULL;
- char *errors = NULL;
- char *newline = NULL;
- int line_buffering = 0;
- _PyIO_State *state = IO_STATE;
-
- PyObject *res;
- int r;
-
- self->ok = 0;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|zzzi:fileio",
- kwlist, &buffer, &encoding, &errors,
- &newline, &line_buffering))
- return -1;
-
- if (newline && newline[0] != '0円'
- && !(newline[0] == '\n' && newline[1] == '0円')
- && !(newline[0] == '\r' && newline[1] == '0円')
- && !(newline[0] == '\r' && newline[1] == '\n' && newline[2] == '0円')) {
- PyErr_Format(PyExc_ValueError,
- "illegal newline value: %s", newline);
- return -1;
- }
-
- Py_CLEAR(self->buffer);
- Py_CLEAR(self->encoding);
- Py_CLEAR(self->encoder);
- Py_CLEAR(self->decoder);
- Py_CLEAR(self->readnl);
- Py_CLEAR(self->decoded_chars);
- Py_CLEAR(self->pending_bytes);
- Py_CLEAR(self->snapshot);
- Py_CLEAR(self->errors);
- Py_CLEAR(self->raw);
- self->decoded_chars_used = 0;
- self->pending_bytes_count = 0;
- self->encodefunc = NULL;
-
- if (encoding == NULL) {
- /* Try os.device_encoding(fileno) */
- PyObject *fileno;
- fileno = PyObject_CallMethod(buffer, "fileno", NULL);
- /* Ignore only AttributeError and UnsupportedOperation */
- if (fileno == NULL) {
- if (PyErr_ExceptionMatches(PyExc_AttributeError) ||
- PyErr_ExceptionMatches(state->unsupported_operation)) {
- PyErr_Clear();
- }
- else {
- goto error;
- }
- }
- else {
- self->encoding = PyObject_CallMethod(state->os_module,
- "device_encoding",
- "N", fileno);
- if (self->encoding == NULL)
- goto error;
- else if (!PyUnicode_Check(self->encoding))
- Py_CLEAR(self->encoding);
- }
- }
- if (encoding == NULL && self->encoding == NULL) {
- if (state->locale_module == NULL) {
- state->locale_module = PyImport_ImportModule("locale");
- if (state->locale_module == NULL)
- goto catch_ImportError;
- else
- goto use_locale;
- }
- else {
- use_locale:
- self->encoding = PyObject_CallMethod(
- state->locale_module, "getpreferredencoding", NULL);
- if (self->encoding == NULL) {
- catch_ImportError:
- /*
- Importing locale can raise a ImportError because of
- _functools, and locale.getpreferredencoding can raise a
- ImportError if _locale is not available. These will happen
- during module building.
- */
- if (PyErr_ExceptionMatches(PyExc_ImportError)) {
- PyErr_Clear();
- self->encoding = PyUnicode_FromString("ascii");
- }
- else
- goto error;
- }
- else if (!PyUnicode_Check(self->encoding))
- Py_CLEAR(self->encoding);
- }
- }
- if (self->encoding != NULL)
- encoding = _PyUnicode_AsString(self->encoding);
- else if (encoding != NULL) {
- self->encoding = PyUnicode_FromString(encoding);
- if (self->encoding == NULL)
- goto error;
- }
- else {
- PyErr_SetString(PyExc_IOError,
- "could not determine default encoding");
- }
-
- if (errors == NULL)
- errors = "strict";
- self->errors = PyBytes_FromString(errors);
- if (self->errors == NULL)
- goto error;
-
- self->chunk_size = 8192;
- self->readuniversal = (newline == NULL || newline[0] == '0円');
- self->line_buffering = line_buffering;
- self->readtranslate = (newline == NULL);
- if (newline) {
- self->readnl = PyUnicode_FromString(newline);
- if (self->readnl == NULL)
- return -1;
- }
- self->writetranslate = (newline == NULL || newline[0] != '0円');
- if (!self->readuniversal && self->readnl) {
- self->writenl = _PyUnicode_AsString(self->readnl);
- if (!strcmp(self->writenl, "\n"))
- self->writenl = NULL;
- }
-#ifdef MS_WINDOWS
- else
- self->writenl = "\r\n";
-#endif
-
- /* Build the decoder object */
- res = PyObject_CallMethod(buffer, "readable", NULL);
- if (res == NULL)
- goto error;
- r = PyObject_IsTrue(res);
- Py_DECREF(res);
- if (r == -1)
- goto error;
- if (r == 1) {
- self->decoder = PyCodec_IncrementalDecoder(
- encoding, errors);
- if (self->decoder == NULL)
- goto error;
-
- if (self->readuniversal) {
- PyObject *incrementalDecoder = PyObject_CallFunction(
- (PyObject *)&PyIncrementalNewlineDecoder_Type,
- "Oi", self->decoder, (int)self->readtranslate);
- if (incrementalDecoder == NULL)
- goto error;
- Py_CLEAR(self->decoder);
- self->decoder = incrementalDecoder;
- }
- }
-
- /* Build the encoder object */
- res = PyObject_CallMethod(buffer, "writable", NULL);
- if (res == NULL)
- goto error;
- r = PyObject_IsTrue(res);
- Py_DECREF(res);
- if (r == -1)
- goto error;
- if (r == 1) {
- PyObject *ci;
- self->encoder = PyCodec_IncrementalEncoder(
- encoding, errors);
- if (self->encoder == NULL)
- goto error;
- /* Get the normalized named of the codec */
- ci = _PyCodec_Lookup(encoding);
- if (ci == NULL)
- goto error;
- res = PyObject_GetAttrString(ci, "name");
- Py_DECREF(ci);
- if (res == NULL)
- PyErr_Clear();
- else if (PyUnicode_Check(res)) {
- encodefuncentry *e = encodefuncs;
- while (e->name != NULL) {
- if (!PyUnicode_CompareWithASCIIString(res, e->name)) {
- self->encodefunc = e->encodefunc;
- break;
- }
- e++;
- }
- }
- Py_XDECREF(res);
- }
-
- self->buffer = buffer;
- Py_INCREF(buffer);
-
- if (Py_TYPE(buffer) == &PyBufferedReader_Type ||
- Py_TYPE(buffer) == &PyBufferedWriter_Type ||
- Py_TYPE(buffer) == &PyBufferedRandom_Type) {
- raw = PyObject_GetAttrString(buffer, "raw");
- /* Cache the raw FileIO object to speed up 'closed' checks */
- if (raw == NULL)
- PyErr_Clear();
- else if (Py_TYPE(raw) == &PyFileIO_Type)
- self->raw = raw;
- else
- Py_DECREF(raw);
- }
-
- res = PyObject_CallMethod(buffer, "seekable", NULL);
- if (res == NULL)
- goto error;
- self->seekable = self->telling = PyObject_IsTrue(res);
- Py_DECREF(res);
-
- self->ok = 1;
- return 0;
-
- error:
- return -1;
-}
-
-static int
-_TextIOWrapper_clear(PyTextIOWrapperObject *self)
-{
- if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0)
- return -1;
- self->ok = 0;
- Py_CLEAR(self->buffer);
- Py_CLEAR(self->encoding);
- Py_CLEAR(self->encoder);
- Py_CLEAR(self->decoder);
- Py_CLEAR(self->readnl);
- Py_CLEAR(self->decoded_chars);
- Py_CLEAR(self->pending_bytes);
- Py_CLEAR(self->snapshot);
- Py_CLEAR(self->errors);
- Py_CLEAR(self->raw);
- return 0;
-}
-
-static void
-TextIOWrapper_dealloc(PyTextIOWrapperObject *self)
-{
- if (_TextIOWrapper_clear(self) < 0)
- return;
- _PyObject_GC_UNTRACK(self);
- if (self->weakreflist != NULL)
- PyObject_ClearWeakRefs((PyObject *)self);
- Py_CLEAR(self->dict);
- Py_TYPE(self)->tp_free((PyObject *)self);
-}
-
-static int
-TextIOWrapper_traverse(PyTextIOWrapperObject *self, visitproc visit, void *arg)
-{
- Py_VISIT(self->buffer);
- Py_VISIT(self->encoding);
- Py_VISIT(self->encoder);
- Py_VISIT(self->decoder);
- Py_VISIT(self->readnl);
- Py_VISIT(self->decoded_chars);
- Py_VISIT(self->pending_bytes);
- Py_VISIT(self->snapshot);
- Py_VISIT(self->errors);
- Py_VISIT(self->raw);
-
- Py_VISIT(self->dict);
- return 0;
-}
-
-static int
-TextIOWrapper_clear(PyTextIOWrapperObject *self)
-{
- if (_TextIOWrapper_clear(self) < 0)
- return -1;
- Py_CLEAR(self->dict);
- return 0;
-}
-
-static PyObject *
-TextIOWrapper_closed_get(PyTextIOWrapperObject *self, void *context);
-
-/* This macro takes some shortcuts to make the common case faster. */
-#define CHECK_CLOSED(self) \
- do { \
- int r; \
- PyObject *_res; \
- if (Py_TYPE(self) == &PyTextIOWrapper_Type) { \
- if (self->raw != NULL) \
- r = _PyFileIO_closed(self->raw); \
- else { \
- _res = TextIOWrapper_closed_get(self, NULL); \
- if (_res == NULL) \
- return NULL; \
- r = PyObject_IsTrue(_res); \
- Py_DECREF(_res); \
- if (r < 0) \
- return NULL; \
- } \
- if (r > 0) { \
- PyErr_SetString(PyExc_ValueError, \
- "I/O operation on closed file."); \
- return NULL; \
- } \
- } \
- else if (_PyIOBase_checkClosed((PyObject *)self, Py_True) == NULL) \
- return NULL; \
- } while (0)
-
-#define CHECK_INITIALIZED(self) \
- if (self->ok <= 0) { \
- PyErr_SetString(PyExc_ValueError, \
- "I/O operation on uninitialized object"); \
- return NULL; \
- }
-
-#define CHECK_INITIALIZED_INT(self) \
- if (self->ok <= 0) { \
- PyErr_SetString(PyExc_ValueError, \
- "I/O operation on uninitialized object"); \
- return -1; \
- }
-
-
-Py_LOCAL_INLINE(const Py_UNICODE *)
-findchar(const Py_UNICODE *s, Py_ssize_t size, Py_UNICODE ch)
-{
- /* like wcschr, but doesn't stop at NULL characters */
- while (size-- > 0) {
- if (*s == ch)
- return s;
- s++;
- }
- return NULL;
-}
-
-/* Flush the internal write buffer. This doesn't explicitly flush the
- underlying buffered object, though. */
-static int
-_TextIOWrapper_writeflush(PyTextIOWrapperObject *self)
-{
- PyObject *b, *ret;
-
- if (self->pending_bytes == NULL)
- return 0;
- b = _PyBytes_Join(_PyIO_empty_bytes, self->pending_bytes);
- if (b == NULL)
- return -1;
- ret = PyObject_CallMethodObjArgs(self->buffer,
- _PyIO_str_write, b, NULL);
- Py_DECREF(b);
- if (ret == NULL)
- return -1;
- Py_DECREF(ret);
- Py_CLEAR(self->pending_bytes);
- self->pending_bytes_count = 0;
- return 0;
-}
-
-static PyObject *
-TextIOWrapper_write(PyTextIOWrapperObject *self, PyObject *args)
-{
- PyObject *ret;
- PyObject *text; /* owned reference */
- PyObject *b;
- Py_ssize_t textlen;
- int haslf = 0;
- int needflush = 0;
-
- CHECK_INITIALIZED(self);
-
- if (!PyArg_ParseTuple(args, "U:write", &text)) {
- return NULL;
- }
-
- CHECK_CLOSED(self);
-
- Py_INCREF(text);
-
- textlen = PyUnicode_GetSize(text);
-
- if ((self->writetranslate && self->writenl != NULL) || self->line_buffering)
- if (findchar(PyUnicode_AS_UNICODE(text),
- PyUnicode_GET_SIZE(text), '\n'))
- haslf = 1;
-
- if (haslf && self->writetranslate && self->writenl != NULL) {
- PyObject *newtext = PyObject_CallMethod(
- text, "replace", "ss", "\n", self->writenl);
- Py_DECREF(text);
- if (newtext == NULL)
- return NULL;
- text = newtext;
- }
-
- if (self->line_buffering &&
- (haslf ||
- findchar(PyUnicode_AS_UNICODE(text),
- PyUnicode_GET_SIZE(text), '\r')))
- needflush = 1;
-
- /* XXX What if we were just reading? */
- if (self->encodefunc != NULL)
- b = (*self->encodefunc)((PyObject *) self, text);
- else
- b = PyObject_CallMethodObjArgs(self->encoder,
- _PyIO_str_encode, text, NULL);
- Py_DECREF(text);
- if (b == NULL)
- return NULL;
-
- if (self->pending_bytes == NULL) {
- self->pending_bytes = PyList_New(0);
- if (self->pending_bytes == NULL) {
- Py_DECREF(b);
- return NULL;
- }
- self->pending_bytes_count = 0;
- }
- if (PyList_Append(self->pending_bytes, b) < 0) {
- Py_DECREF(b);
- return NULL;
- }
- self->pending_bytes_count += PyBytes_GET_SIZE(b);
- Py_DECREF(b);
- if (self->pending_bytes_count > self->chunk_size || needflush) {
- if (_TextIOWrapper_writeflush(self) < 0)
- return NULL;
- }
-
- if (needflush) {
- ret = PyObject_CallMethodObjArgs(self->buffer, _PyIO_str_flush, NULL);
- if (ret == NULL)
- return NULL;
- Py_DECREF(ret);
- }
-
- Py_CLEAR(self->snapshot);
-
- if (self->decoder) {
- ret = PyObject_CallMethod(self->decoder, "reset", NULL);
- if (ret == NULL)
- return NULL;
- Py_DECREF(ret);
- }
-
- return PyLong_FromSsize_t(textlen);
-}
-
-/* Steal a reference to chars and store it in the decoded_char buffer;
- */
-static void
-TextIOWrapper_set_decoded_chars(PyTextIOWrapperObject *self, PyObject *chars)
-{
- Py_CLEAR(self->decoded_chars);
- self->decoded_chars = chars;
- self->decoded_chars_used = 0;
-}
-
-static PyObject *
-TextIOWrapper_get_decoded_chars(PyTextIOWrapperObject *self, Py_ssize_t n)
-{
- PyObject *chars;
- Py_ssize_t avail;
-
- if (self->decoded_chars == NULL)
- return PyUnicode_FromStringAndSize(NULL, 0);
-
- avail = (PyUnicode_GET_SIZE(self->decoded_chars)
- - self->decoded_chars_used);
-
- assert(avail >= 0);
-
- if (n < 0 || n > avail)
- n = avail;
-
- if (self->decoded_chars_used > 0 || n < avail) {
- chars = PyUnicode_FromUnicode(
- PyUnicode_AS_UNICODE(self->decoded_chars)
- + self->decoded_chars_used, n);
- if (chars == NULL)
- return NULL;
- }
- else {
- chars = self->decoded_chars;
- Py_INCREF(chars);
- }
-
- self->decoded_chars_used += n;
- return chars;
-}
-
-/* Read and decode the next chunk of data from the BufferedReader.
- */
-static int
-TextIOWrapper_read_chunk(PyTextIOWrapperObject *self)
-{
- PyObject *dec_buffer = NULL;
- PyObject *dec_flags = NULL;
- PyObject *input_chunk = NULL;
- PyObject *decoded_chars, *chunk_size;
- int eof;
-
- /* 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 == NULL) {
- PyErr_SetString(PyExc_ValueError, "no decoder");
- return -1;
- }
-
- if (self->telling) {
- /* To prepare for tell(), we need to snapshot a point in the file
- * where the decoder's input buffer is empty.
- */
-
- PyObject *state = PyObject_CallMethodObjArgs(self->decoder,
- _PyIO_str_getstate, NULL);
- if (state == NULL)
- return -1;
- /* Given this, we know there was a valid snapshot point
- * len(dec_buffer) bytes ago with decoder state (b'', dec_flags).
- */
- if (PyArg_Parse(state, "(OO)", &dec_buffer, &dec_flags) < 0) {
- Py_DECREF(state);
- return -1;
- }
- Py_INCREF(dec_buffer);
- Py_INCREF(dec_flags);
- Py_DECREF(state);
- }
-
- /* Read a chunk, decode it, and put the result in self._decoded_chars. */
- chunk_size = PyLong_FromSsize_t(self->chunk_size);
- if (chunk_size == NULL)
- goto fail;
- input_chunk = PyObject_CallMethodObjArgs(self->buffer,
- _PyIO_str_read1, chunk_size, NULL);
- Py_DECREF(chunk_size);
- if (input_chunk == NULL)
- goto fail;
- assert(PyBytes_Check(input_chunk));
-
- eof = (PyBytes_Size(input_chunk) == 0);
-
- if (Py_TYPE(self->decoder) == &PyIncrementalNewlineDecoder_Type) {
- decoded_chars = _PyIncrementalNewlineDecoder_decode(
- self->decoder, input_chunk, eof);
- }
- else {
- decoded_chars = PyObject_CallMethodObjArgs(self->decoder,
- _PyIO_str_decode, input_chunk, eof ? Py_True : Py_False, NULL);
- }
-
- /* TODO sanity check: isinstance(decoded_chars, unicode) */
- if (decoded_chars == NULL)
- goto fail;
- TextIOWrapper_set_decoded_chars(self, decoded_chars);
- if (PyUnicode_GET_SIZE(decoded_chars) > 0)
- eof = 0;
-
- 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.
- */
- PyObject *next_input = PyNumber_Add(dec_buffer, input_chunk);
- if (next_input == NULL)
- goto fail;
- assert (PyBytes_Check(next_input));
- Py_DECREF(dec_buffer);
- Py_CLEAR(self->snapshot);
- self->snapshot = Py_BuildValue("NN", dec_flags, next_input);
- }
- Py_DECREF(input_chunk);
-
- return (eof == 0);
-
- fail:
- Py_XDECREF(dec_buffer);
- Py_XDECREF(dec_flags);
- Py_XDECREF(input_chunk);
- return -1;
-}
-
-static PyObject *
-TextIOWrapper_read(PyTextIOWrapperObject *self, PyObject *args)
-{
- Py_ssize_t n = -1;
- PyObject *result = NULL, *chunks = NULL;
-
- CHECK_INITIALIZED(self);
-
- if (!PyArg_ParseTuple(args, "|n:read", &n))
- return NULL;
-
- CHECK_CLOSED(self);
-
- if (_TextIOWrapper_writeflush(self) < 0)
- return NULL;
-
- if (n < 0) {
- /* Read everything */
- PyObject *bytes = PyObject_CallMethod(self->buffer, "read", NULL);
- PyObject *decoded;
- if (bytes == NULL)
- goto fail;
- decoded = PyObject_CallMethodObjArgs(self->decoder, _PyIO_str_decode,
- bytes, Py_True, NULL);
- Py_DECREF(bytes);
- if (decoded == NULL)
- goto fail;
-
- result = TextIOWrapper_get_decoded_chars(self, -1);
-
- if (result == NULL) {
- Py_DECREF(decoded);
- return NULL;
- }
-
- PyUnicode_AppendAndDel(&result, decoded);
- if (result == NULL)
- goto fail;
-
- Py_CLEAR(self->snapshot);
- return result;
- }
- else {
- int res = 1;
- Py_ssize_t remaining = n;
-
- result = TextIOWrapper_get_decoded_chars(self, n);
- if (result == NULL)
- goto fail;
- remaining -= PyUnicode_GET_SIZE(result);
-
- /* Keep reading chunks until we have n characters to return */
- while (remaining > 0) {
- res = TextIOWrapper_read_chunk(self);
- if (res < 0)
- goto fail;
- if (res == 0) /* EOF */
- break;
- if (chunks == NULL) {
- chunks = PyList_New(0);
- if (chunks == NULL)
- goto fail;
- }
- if (PyList_Append(chunks, result) < 0)
- goto fail;
- Py_DECREF(result);
- result = TextIOWrapper_get_decoded_chars(self, remaining);
- if (result == NULL)
- goto fail;
- remaining -= PyUnicode_GET_SIZE(result);
- }
- if (chunks != NULL) {
- if (result != NULL && PyList_Append(chunks, result) < 0)
- goto fail;
- Py_CLEAR(result);
- result = PyUnicode_Join(_PyIO_empty_str, chunks);
- if (result == NULL)
- goto fail;
- Py_CLEAR(chunks);
- }
- return result;
- }
- fail:
- Py_XDECREF(result);
- Py_XDECREF(chunks);
- return NULL;
-}
-
-
-/* NOTE: `end` must point to the real end of the Py_UNICODE storage,
- that is to the NUL character. Otherwise the function will produce
- incorrect results. */
-static Py_UNICODE *
-find_control_char(Py_UNICODE *start, Py_UNICODE *end, Py_UNICODE ch)
-{
- Py_UNICODE *s = start;
- for (;;) {
- while (*s > ch)
- s++;
- if (*s == ch)
- return s;
- if (s == end)
- return NULL;
- s++;
- }
-}
-
-Py_ssize_t
-_PyIO_find_line_ending(
- int translated, int universal, PyObject *readnl,
- Py_UNICODE *start, Py_UNICODE *end, Py_ssize_t *consumed)
-{
- Py_ssize_t len = end - start;
-
- if (translated) {
- /* Newlines are already translated, only search for \n */
- Py_UNICODE *pos = find_control_char(start, end, '\n');
- if (pos != NULL)
- return pos - start + 1;
- else {
- *consumed = len;
- return -1;
- }
- }
- else if (universal) {
- /* Universal newline search. Find any of \r, \r\n, \n
- * The decoder ensures that \r\n are not split in two pieces
- */
- Py_UNICODE *s = start;
- for (;;) {
- Py_UNICODE ch;
- /* Fast path for non-control chars. The loop always ends
- since the Py_UNICODE storage is NUL-terminated. */
- while (*s > '\r')
- s++;
- if (s >= end) {
- *consumed = len;
- return -1;
- }
- ch = *s++;
- if (ch == '\n')
- return s - start;
- if (ch == '\r') {
- if (*s == '\n')
- return s - start + 1;
- else
- return s - start;
- }
- }
- }
- else {
- /* Non-universal mode. */
- Py_ssize_t readnl_len = PyUnicode_GET_SIZE(readnl);
- Py_UNICODE *nl = PyUnicode_AS_UNICODE(readnl);
- if (readnl_len == 1) {
- Py_UNICODE *pos = find_control_char(start, end, nl[0]);
- if (pos != NULL)
- return pos - start + 1;
- *consumed = len;
- return -1;
- }
- else {
- Py_UNICODE *s = start;
- Py_UNICODE *e = end - readnl_len + 1;
- Py_UNICODE *pos;
- if (e < s)
- e = s;
- while (s < e) {
- Py_ssize_t i;
- Py_UNICODE *pos = find_control_char(s, end, nl[0]);
- if (pos == NULL || pos >= e)
- break;
- for (i = 1; i < readnl_len; i++) {
- if (pos[i] != nl[i])
- break;
- }
- if (i == readnl_len)
- return pos - start + readnl_len;
- s = pos + 1;
- }
- pos = find_control_char(e, end, nl[0]);
- if (pos == NULL)
- *consumed = len;
- else
- *consumed = pos - start;
- return -1;
- }
- }
-}
-
-static PyObject *
-_TextIOWrapper_readline(PyTextIOWrapperObject *self, Py_ssize_t limit)
-{
- PyObject *line = NULL, *chunks = NULL, *remaining = NULL;
- Py_ssize_t start, endpos, chunked, offset_to_buffer;
- int res;
-
- CHECK_CLOSED(self);
-
- if (_TextIOWrapper_writeflush(self) < 0)
- return NULL;
-
- chunked = 0;
-
- while (1) {
- Py_UNICODE *ptr;
- Py_ssize_t line_len;
- Py_ssize_t consumed = 0;
-
- /* First, get some data if necessary */
- res = 1;
- while (!self->decoded_chars ||
- !PyUnicode_GET_SIZE(self->decoded_chars)) {
- res = TextIOWrapper_read_chunk(self);
- if (res < 0)
- goto error;
- if (res == 0)
- break;
- }
- if (res == 0) {
- /* end of file */
- TextIOWrapper_set_decoded_chars(self, NULL);
- Py_CLEAR(self->snapshot);
- start = endpos = offset_to_buffer = 0;
- break;
- }
-
- if (remaining == NULL) {
- line = self->decoded_chars;
- start = self->decoded_chars_used;
- offset_to_buffer = 0;
- Py_INCREF(line);
- }
- else {
- assert(self->decoded_chars_used == 0);
- line = PyUnicode_Concat(remaining, self->decoded_chars);
- start = 0;
- offset_to_buffer = PyUnicode_GET_SIZE(remaining);
- Py_CLEAR(remaining);
- if (line == NULL)
- goto error;
- }
-
- ptr = PyUnicode_AS_UNICODE(line);
- line_len = PyUnicode_GET_SIZE(line);
-
- endpos = _PyIO_find_line_ending(
- self->readtranslate, self->readuniversal, self->readnl,
- ptr + start, ptr + line_len, &consumed);
- if (endpos >= 0) {
- endpos += start;
- if (limit >= 0 && (endpos - start) + chunked >= limit)
- endpos = start + limit - chunked;
- break;
- }
-
- /* We can put aside up to `endpos` */
- endpos = consumed + start;
- if (limit >= 0 && (endpos - start) + chunked >= limit) {
- /* Didn't find line ending, but reached length limit */
- endpos = start + limit - chunked;
- break;
- }
-
- if (endpos > start) {
- /* No line ending seen yet - put aside current data */
- PyObject *s;
- if (chunks == NULL) {
- chunks = PyList_New(0);
- if (chunks == NULL)
- goto error;
- }
- s = PyUnicode_FromUnicode(ptr + start, endpos - start);
- if (s == NULL)
- goto error;
- if (PyList_Append(chunks, s) < 0) {
- Py_DECREF(s);
- goto error;
- }
- chunked += PyUnicode_GET_SIZE(s);
- Py_DECREF(s);
- }
- /* There may be some remaining bytes we'll have to prepend to the
- next chunk of data */
- if (endpos < line_len) {
- remaining = PyUnicode_FromUnicode(
- ptr + endpos, line_len - endpos);
- if (remaining == NULL)
- goto error;
- }
- Py_CLEAR(line);
- /* We have consumed the buffer */
- TextIOWrapper_set_decoded_chars(self, NULL);
- }
-
- if (line != NULL) {
- /* Our line ends in the current buffer */
- self->decoded_chars_used = endpos - offset_to_buffer;
- if (start > 0 || endpos < PyUnicode_GET_SIZE(line)) {
- if (start == 0 && Py_REFCNT(line) == 1) {
- if (PyUnicode_Resize(&line, endpos) < 0)
- goto error;
- }
- else {
- PyObject *s = PyUnicode_FromUnicode(
- PyUnicode_AS_UNICODE(line) + start, endpos - start);
- Py_CLEAR(line);
- if (s == NULL)
- goto error;
- line = s;
- }
- }
- }
- if (remaining != NULL) {
- if (chunks == NULL) {
- chunks = PyList_New(0);
- if (chunks == NULL)
- goto error;
- }
- if (PyList_Append(chunks, remaining) < 0)
- goto error;
- Py_CLEAR(remaining);
- }
- if (chunks != NULL) {
- if (line != NULL && PyList_Append(chunks, line) < 0)
- goto error;
- Py_CLEAR(line);
- line = PyUnicode_Join(_PyIO_empty_str, chunks);
- if (line == NULL)
- goto error;
- Py_DECREF(chunks);
- }
- if (line == NULL)
- line = PyUnicode_FromStringAndSize(NULL, 0);
-
- return line;
-
- error:
- Py_XDECREF(chunks);
- Py_XDECREF(remaining);
- Py_XDECREF(line);
- return NULL;
-}
-
-static PyObject *
-TextIOWrapper_readline(PyTextIOWrapperObject *self, PyObject *args)
-{
- Py_ssize_t limit = -1;
-
- CHECK_INITIALIZED(self);
- if (!PyArg_ParseTuple(args, "|n:readline", &limit)) {
- return NULL;
- }
- return _TextIOWrapper_readline(self, limit);
-}
-
-/* Seek and Tell */
-
-typedef struct {
- Py_off_t start_pos;
- int dec_flags;
- int bytes_to_feed;
- int chars_to_skip;
- char need_eof;
-} CookieStruct;
-
-/*
- To speed up cookie packing/unpacking, we store the fields in a temporary
- string and call _PyLong_FromByteArray() or _PyLong_AsByteArray (resp.).
- The following macros define at which offsets in the intermediary byte
- string the various CookieStruct fields will be stored.
- */
-
-#define COOKIE_BUF_LEN (sizeof(Py_off_t) + 3 * sizeof(int) + sizeof(char))
-
-#if defined(WORDS_BIGENDIAN)
-
-# define IS_LITTLE_ENDIAN 0
-
-/* We want the least significant byte of start_pos to also be the least
- significant byte of the cookie, which means that in big-endian mode we
- must copy the fields in reverse order. */
-
-# define OFF_START_POS (sizeof(char) + 3 * sizeof(int))
-# define OFF_DEC_FLAGS (sizeof(char) + 2 * sizeof(int))
-# define OFF_BYTES_TO_FEED (sizeof(char) + sizeof(int))
-# define OFF_CHARS_TO_SKIP (sizeof(char))
-# define OFF_NEED_EOF 0
-
-#else
-
-# define IS_LITTLE_ENDIAN 1
-
-/* Little-endian mode: the least significant byte of start_pos will
- naturally end up the least significant byte of the cookie. */
-
-# define OFF_START_POS 0
-# define OFF_DEC_FLAGS (sizeof(Py_off_t))
-# define OFF_BYTES_TO_FEED (sizeof(Py_off_t) + sizeof(int))
-# define OFF_CHARS_TO_SKIP (sizeof(Py_off_t) + 2 * sizeof(int))
-# define OFF_NEED_EOF (sizeof(Py_off_t) + 3 * sizeof(int))
-
-#endif
-
-static int
-TextIOWrapper_parseCookie(CookieStruct *cookie, PyObject *cookieObj)
-{
- unsigned char buffer[COOKIE_BUF_LEN];
- PyLongObject *cookieLong = (PyLongObject *)PyNumber_Long(cookieObj);
- if (cookieLong == NULL)
- return -1;
-
- if (_PyLong_AsByteArray(cookieLong, buffer, sizeof(buffer),
- IS_LITTLE_ENDIAN, 0) < 0) {
- Py_DECREF(cookieLong);
- return -1;
- }
- Py_DECREF(cookieLong);
-
- memcpy(&cookie->start_pos, buffer + OFF_START_POS, sizeof(cookie->start_pos));
- memcpy(&cookie->dec_flags, buffer + OFF_DEC_FLAGS, sizeof(cookie->dec_flags));
- memcpy(&cookie->bytes_to_feed, buffer + OFF_BYTES_TO_FEED, sizeof(cookie->bytes_to_feed));
- memcpy(&cookie->chars_to_skip, buffer + OFF_CHARS_TO_SKIP, sizeof(cookie->chars_to_skip));
- memcpy(&cookie->need_eof, buffer + OFF_NEED_EOF, sizeof(cookie->need_eof));
-
- return 0;
-}
-
-static PyObject *
-TextIOWrapper_buildCookie(CookieStruct *cookie)
-{
- unsigned char buffer[COOKIE_BUF_LEN];
-
- memcpy(buffer + OFF_START_POS, &cookie->start_pos, sizeof(cookie->start_pos));
- memcpy(buffer + OFF_DEC_FLAGS, &cookie->dec_flags, sizeof(cookie->dec_flags));
- memcpy(buffer + OFF_BYTES_TO_FEED, &cookie->bytes_to_feed, sizeof(cookie->bytes_to_feed));
- memcpy(buffer + OFF_CHARS_TO_SKIP, &cookie->chars_to_skip, sizeof(cookie->chars_to_skip));
- memcpy(buffer + OFF_NEED_EOF, &cookie->need_eof, sizeof(cookie->need_eof));
-
- return _PyLong_FromByteArray(buffer, sizeof(buffer), IS_LITTLE_ENDIAN, 0);
-}
-#undef IS_LITTLE_ENDIAN
-
-static int
-_TextIOWrapper_decoder_setstate(PyTextIOWrapperObject *self,
- CookieStruct *cookie)
-{
- PyObject *res;
- /* When seeking to the start of the stream, we call decoder.reset()
- rather than decoder.getstate().
- This is for a few decoders such as utf-16 for which the state value
- at start is not (b"", 0) but e.g. (b"", 2) (meaning, in the case of
- utf-16, that we are expecting a BOM).
- */
- if (cookie->start_pos == 0 && cookie->dec_flags == 0)
- res = PyObject_CallMethodObjArgs(self->decoder, _PyIO_str_reset, NULL);
- else
- res = PyObject_CallMethod(self->decoder, "setstate",
- "((yi))", "", cookie->dec_flags);
- if (res == NULL)
- return -1;
- Py_DECREF(res);
- return 0;
-}
-
-static PyObject *
-TextIOWrapper_seek(PyTextIOWrapperObject *self, PyObject *args)
-{
- PyObject *cookieObj, *posobj;
- CookieStruct cookie;
- int whence = 0;
- static PyObject *zero = NULL;
- PyObject *res;
- int cmp;
-
- CHECK_INITIALIZED(self);
-
- if (zero == NULL) {
- zero = PyLong_FromLong(0L);
- if (zero == NULL)
- return NULL;
- }
-
- if (!PyArg_ParseTuple(args, "O|i:seek", &cookieObj, &whence))
- return NULL;
- CHECK_CLOSED(self);
-
- Py_INCREF(cookieObj);
-
- if (!self->seekable) {
- PyErr_SetString(PyExc_IOError,
- "underlying stream is not seekable");
- goto fail;
- }
-
- if (whence == 1) {
- /* seek relative to current position */
- cmp = PyObject_RichCompareBool(cookieObj, zero, Py_EQ);
- if (cmp < 0)
- goto fail;
-
- if (cmp == 0) {
- PyErr_SetString(PyExc_IOError,
- "can't do nonzero cur-relative seeks");
- goto fail;
- }
-
- /* Seeking to the current position should attempt to
- * sync the underlying buffer with the current position.
- */
- Py_DECREF(cookieObj);
- cookieObj = PyObject_CallMethod((PyObject *)self, "tell", NULL);
- if (cookieObj == NULL)
- goto fail;
- }
- else if (whence == 2) {
- /* seek relative to end of file */
-
- cmp = PyObject_RichCompareBool(cookieObj, zero, Py_EQ);
- if (cmp < 0)
- goto fail;
-
- if (cmp == 0) {
- PyErr_SetString(PyExc_IOError,
- "can't do nonzero end-relative seeks");
- goto fail;
- }
-
- res = PyObject_CallMethod((PyObject *)self, "flush", NULL);
- if (res == NULL)
- goto fail;
- Py_DECREF(res);
-
- TextIOWrapper_set_decoded_chars(self, NULL);
- Py_CLEAR(self->snapshot);
- if (self->decoder) {
- res = PyObject_CallMethod(self->decoder, "reset", NULL);
- if (res == NULL)
- goto fail;
- Py_DECREF(res);
- }
-
- res = PyObject_CallMethod(self->buffer, "seek", "ii", 0, 2);
- Py_XDECREF(cookieObj);
- return res;
- }
- else if (whence != 0) {
- PyErr_Format(PyExc_ValueError,
- "invalid whence (%d, should be 0, 1 or 2)", whence);
- goto fail;
- }
-
- cmp = PyObject_RichCompareBool(cookieObj, zero, Py_LT);
- if (cmp < 0)
- goto fail;
-
- if (cmp == 1) {
- PyErr_Format(PyExc_ValueError,
- "negative seek position %R", cookieObj);
- goto fail;
- }
-
- res = PyObject_CallMethodObjArgs((PyObject *)self, _PyIO_str_flush, NULL);
- if (res == NULL)
- goto fail;
- Py_DECREF(res);
-
- /* The strategy of seek() is to go back to the safe start point
- * and replay the effect of read(chars_to_skip) from there.
- */
- if (TextIOWrapper_parseCookie(&cookie, cookieObj) < 0)
- goto fail;
-
- /* Seek back to the safe start point. */
- posobj = PyLong_FromOff_t(cookie.start_pos);
- if (posobj == NULL)
- goto fail;
- res = PyObject_CallMethodObjArgs(self->buffer,
- _PyIO_str_seek, posobj, NULL);
- Py_DECREF(posobj);
- if (res == NULL)
- goto fail;
- Py_DECREF(res);
-
- TextIOWrapper_set_decoded_chars(self, NULL);
- Py_CLEAR(self->snapshot);
-
- /* Restore the decoder to its state from the safe start point. */
- if (self->decoder) {
- if (_TextIOWrapper_decoder_setstate(self, &cookie) < 0)
- goto fail;
- }
-
- if (cookie.chars_to_skip) {
- /* Just like _read_chunk, feed the decoder and save a snapshot. */
- PyObject *input_chunk = PyObject_CallMethod(
- self->buffer, "read", "i", cookie.bytes_to_feed);
- PyObject *decoded;
-
- if (input_chunk == NULL)
- goto fail;
-
- assert (PyBytes_Check(input_chunk));
-
- self->snapshot = Py_BuildValue("iN", cookie.dec_flags, input_chunk);
- if (self->snapshot == NULL) {
- Py_DECREF(input_chunk);
- goto fail;
- }
-
- decoded = PyObject_CallMethod(self->decoder, "decode",
- "Oi", input_chunk, (int)cookie.need_eof);
-
- if (decoded == NULL)
- goto fail;
-
- TextIOWrapper_set_decoded_chars(self, decoded);
-
- /* Skip chars_to_skip of the decoded characters. */
- if (PyUnicode_GetSize(self->decoded_chars) < cookie.chars_to_skip) {
- PyErr_SetString(PyExc_IOError, "can't restore logical file position");
- goto fail;
- }
- self->decoded_chars_used = cookie.chars_to_skip;
- }
- else {
- self->snapshot = Py_BuildValue("iy", cookie.dec_flags, "");
- if (self->snapshot == NULL)
- goto fail;
- }
-
- return cookieObj;
- fail:
- Py_XDECREF(cookieObj);
- return NULL;
-
-}
-
-static PyObject *
-TextIOWrapper_tell(PyTextIOWrapperObject *self, PyObject *args)
-{
- PyObject *res;
- PyObject *posobj = NULL;
- CookieStruct cookie = {0,0,0,0,0};
- PyObject *next_input;
- Py_ssize_t chars_to_skip, chars_decoded;
- PyObject *saved_state = NULL;
- char *input, *input_end;
-
- CHECK_INITIALIZED(self);
- CHECK_CLOSED(self);
-
- if (!self->seekable) {
- PyErr_SetString(PyExc_IOError,
- "underlying stream is not seekable");
- goto fail;
- }
- if (!self->telling) {
- PyErr_SetString(PyExc_IOError,
- "telling position disabled by next() call");
- goto fail;
- }
-
- if (_TextIOWrapper_writeflush(self) < 0)
- return NULL;
- res = PyObject_CallMethod((PyObject *)self, "flush", NULL);
- if (res == NULL)
- goto fail;
- Py_DECREF(res);
-
- posobj = PyObject_CallMethod(self->buffer, "tell", NULL);
- if (posobj == NULL)
- goto fail;
-
- if (self->decoder == NULL || self->snapshot == NULL) {
- assert (self->decoded_chars == NULL || PyUnicode_GetSize(self->decoded_chars) == 0);
- return posobj;
- }
-
-#if defined(HAVE_LARGEFILE_SUPPORT)
- cookie.start_pos = PyLong_AsLongLong(posobj);
-#else
- cookie.start_pos = PyLong_AsLong(posobj);
-#endif
- if (PyErr_Occurred())
- goto fail;
-
- /* Skip backward to the snapshot point (see _read_chunk). */
- if (!PyArg_Parse(self->snapshot, "(iO)", &cookie.dec_flags, &next_input))
- goto fail;
-
- assert (PyBytes_Check(next_input));
-
- cookie.start_pos -= PyBytes_GET_SIZE(next_input);
-
- /* How many decoded characters have been used up since the snapshot? */
- if (self->decoded_chars_used == 0) {
- /* We haven't moved from the snapshot point. */
- Py_DECREF(posobj);
- return TextIOWrapper_buildCookie(&cookie);
- }
-
- chars_to_skip = self->decoded_chars_used;
-
- /* Starting from the snapshot position, we will walk the decoder
- * forward until it gives us enough decoded characters.
- */
- saved_state = PyObject_CallMethodObjArgs(self->decoder,
- _PyIO_str_getstate, NULL);
- if (saved_state == NULL)
- goto fail;
-
- /* Note our initial start point. */
- if (_TextIOWrapper_decoder_setstate(self, &cookie) < 0)
- goto fail;
-
- /* 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).
- */
- chars_decoded = 0;
- input = PyBytes_AS_STRING(next_input);
- input_end = input + PyBytes_GET_SIZE(next_input);
- while (input < input_end) {
- PyObject *state;
- char *dec_buffer;
- Py_ssize_t dec_buffer_len;
- int dec_flags;
-
- PyObject *decoded = PyObject_CallMethod(
- self->decoder, "decode", "y#", input, 1);
- if (decoded == NULL)
- goto fail;
- assert (PyUnicode_Check(decoded));
- chars_decoded += PyUnicode_GET_SIZE(decoded);
- Py_DECREF(decoded);
-
- cookie.bytes_to_feed += 1;
-
- state = PyObject_CallMethodObjArgs(self->decoder,
- _PyIO_str_getstate, NULL);
- if (state == NULL)
- goto fail;
- if (!PyArg_Parse(state, "(y#i)", &dec_buffer, &dec_buffer_len, &dec_flags)) {
- Py_DECREF(state);
- goto fail;
- }
- Py_DECREF(state);
-
- if (dec_buffer_len == 0 && chars_decoded <= chars_to_skip) {
- /* Decoder buffer is empty, so this is a safe start point. */
- cookie.start_pos += cookie.bytes_to_feed;
- chars_to_skip -= chars_decoded;
- cookie.dec_flags = dec_flags;
- cookie.bytes_to_feed = 0;
- chars_decoded = 0;
- }
- if (chars_decoded >= chars_to_skip)
- break;
- input++;
- }
- if (input == input_end) {
- /* We didn't get enough decoded data; signal EOF to get more. */
- PyObject *decoded = PyObject_CallMethod(
- self->decoder, "decode", "yi", "", /* final = */ 1);
- if (decoded == NULL)
- goto fail;
- assert (PyUnicode_Check(decoded));
- chars_decoded += PyUnicode_GET_SIZE(decoded);
- Py_DECREF(decoded);
- cookie.need_eof = 1;
-
- if (chars_decoded < chars_to_skip) {
- PyErr_SetString(PyExc_IOError,
- "can't reconstruct logical file position");
- goto fail;
- }
- }
-
- /* finally */
- Py_XDECREF(posobj);
- res = PyObject_CallMethod(self->decoder, "setstate", "(O)", saved_state);
- Py_DECREF(saved_state);
- if (res == NULL)
- return NULL;
- Py_DECREF(res);
-
- /* The returned cookie corresponds to the last safe start point. */
- cookie.chars_to_skip = Py_SAFE_DOWNCAST(chars_to_skip, Py_ssize_t, int);
- return TextIOWrapper_buildCookie(&cookie);
-
- fail:
- Py_XDECREF(posobj);
- if (saved_state) {
- PyObject *type, *value, *traceback;
- PyErr_Fetch(&type, &value, &traceback);
-
- res = PyObject_CallMethod(self->decoder, "setstate", "(O)", saved_state);
- Py_DECREF(saved_state);
- if (res == NULL)
- return NULL;
- Py_DECREF(res);
-
- PyErr_Restore(type, value, traceback);
- }
- return NULL;
-}
-
-static PyObject *
-TextIOWrapper_truncate(PyTextIOWrapperObject *self, PyObject *args)
-{
- PyObject *pos = Py_None;
- PyObject *res;
-
- CHECK_INITIALIZED(self)
- if (!PyArg_ParseTuple(args, "|O:truncate", &pos)) {
- return NULL;
- }
-
- res = PyObject_CallMethodObjArgs((PyObject *) self, _PyIO_str_flush, NULL);
- if (res == NULL)
- return NULL;
- Py_DECREF(res);
-
- if (pos != Py_None) {
- res = PyObject_CallMethodObjArgs((PyObject *) self,
- _PyIO_str_seek, pos, NULL);
- if (res == NULL)
- return NULL;
- Py_DECREF(res);
- }
-
- return PyObject_CallMethodObjArgs(self->buffer, _PyIO_str_truncate, NULL);
-}
-
-static PyObject *
-TextIOWrapper_repr(PyTextIOWrapperObject *self)
-{
- CHECK_INITIALIZED(self);
- return PyUnicode_FromFormat("<TextIOWrapper encoding=%S>", self->encoding);
-}
-
-
-/* Inquiries */
-
-static PyObject *
-TextIOWrapper_fileno(PyTextIOWrapperObject *self, PyObject *args)
-{
- CHECK_INITIALIZED(self);
- return PyObject_CallMethod(self->buffer, "fileno", NULL);
-}
-
-static PyObject *
-TextIOWrapper_seekable(PyTextIOWrapperObject *self, PyObject *args)
-{
- CHECK_INITIALIZED(self);
- return PyObject_CallMethod(self->buffer, "seekable", NULL);
-}
-
-static PyObject *
-TextIOWrapper_readable(PyTextIOWrapperObject *self, PyObject *args)
-{
- CHECK_INITIALIZED(self);
- return PyObject_CallMethod(self->buffer, "readable", NULL);
-}
-
-static PyObject *
-TextIOWrapper_writable(PyTextIOWrapperObject *self, PyObject *args)
-{
- CHECK_INITIALIZED(self);
- return PyObject_CallMethod(self->buffer, "writable", NULL);
-}
-
-static PyObject *
-TextIOWrapper_isatty(PyTextIOWrapperObject *self, PyObject *args)
-{
- CHECK_INITIALIZED(self);
- return PyObject_CallMethod(self->buffer, "isatty", NULL);
-}
-
-static PyObject *
-TextIOWrapper_flush(PyTextIOWrapperObject *self, PyObject *args)
-{
- CHECK_INITIALIZED(self);
- CHECK_CLOSED(self);
- self->telling = self->seekable;
- if (_TextIOWrapper_writeflush(self) < 0)
- return NULL;
- return PyObject_CallMethod(self->buffer, "flush", NULL);
-}
-
-static PyObject *
-TextIOWrapper_close(PyTextIOWrapperObject *self, PyObject *args)
-{
- PyObject *res;
- CHECK_INITIALIZED(self);
- res = PyObject_CallMethod((PyObject *)self, "flush", NULL);
- if (res == NULL) {
- /* If flush() fails, just give up */
- PyErr_Clear();
- }
- else
- Py_DECREF(res);
-
- return PyObject_CallMethod(self->buffer, "close", NULL);
-}
-
-static PyObject *
-TextIOWrapper_iternext(PyTextIOWrapperObject *self)
-{
- PyObject *line;
-
- CHECK_INITIALIZED(self);
-
- self->telling = 0;
- if (Py_TYPE(self) == &PyTextIOWrapper_Type) {
- /* Skip method call overhead for speed */
- line = _TextIOWrapper_readline(self, -1);
- }
- else {
- line = PyObject_CallMethodObjArgs((PyObject *)self,
- _PyIO_str_readline, NULL);
- if (line && !PyUnicode_Check(line)) {
- PyErr_Format(PyExc_IOError,
- "readline() should have returned an str object, "
- "not '%.200s'", Py_TYPE(line)->tp_name);
- Py_DECREF(line);
- return NULL;
- }
- }
-
- if (line == NULL)
- return NULL;
-
- if (PyUnicode_GET_SIZE(line) == 0) {
- /* Reached EOF or would have blocked */
- Py_DECREF(line);
- Py_CLEAR(self->snapshot);
- self->telling = self->seekable;
- return NULL;
- }
-
- return line;
-}
-
-static PyObject *
-TextIOWrapper_name_get(PyTextIOWrapperObject *self, void *context)
-{
- CHECK_INITIALIZED(self);
- return PyObject_GetAttrString(self->buffer, "name");
-}
-
-static PyObject *
-TextIOWrapper_closed_get(PyTextIOWrapperObject *self, void *context)
-{
- CHECK_INITIALIZED(self);
- return PyObject_GetAttr(self->buffer, _PyIO_str_closed);
-}
-
-static PyObject *
-TextIOWrapper_newlines_get(PyTextIOWrapperObject *self, void *context)
-{
- PyObject *res;
- CHECK_INITIALIZED(self);
- if (self->decoder == NULL)
- Py_RETURN_NONE;
- res = PyObject_GetAttr(self->decoder, _PyIO_str_newlines);
- if (res == NULL) {
- PyErr_Clear();
- Py_RETURN_NONE;
- }
- return res;
-}
-
-static PyObject *
-TextIOWrapper_chunk_size_get(PyTextIOWrapperObject *self, void *context)
-{
- CHECK_INITIALIZED(self);
- return PyLong_FromSsize_t(self->chunk_size);
-}
-
-static int
-TextIOWrapper_chunk_size_set(PyTextIOWrapperObject *self,
- PyObject *arg, void *context)
-{
- Py_ssize_t n;
- CHECK_INITIALIZED_INT(self);
- n = PyNumber_AsSsize_t(arg, PyExc_TypeError);
- if (n == -1 && PyErr_Occurred())
- return -1;
- if (n <= 0) {
- PyErr_SetString(PyExc_ValueError,
- "a strictly positive integer is required");
- return -1;
- }
- self->chunk_size = n;
- return 0;
-}
-
-static PyMethodDef TextIOWrapper_methods[] = {
- {"write", (PyCFunction)TextIOWrapper_write, METH_VARARGS},
- {"read", (PyCFunction)TextIOWrapper_read, METH_VARARGS},
- {"readline", (PyCFunction)TextIOWrapper_readline, METH_VARARGS},
- {"flush", (PyCFunction)TextIOWrapper_flush, METH_NOARGS},
- {"close", (PyCFunction)TextIOWrapper_close, METH_NOARGS},
-
- {"fileno", (PyCFunction)TextIOWrapper_fileno, METH_NOARGS},
- {"seekable", (PyCFunction)TextIOWrapper_seekable, METH_NOARGS},
- {"readable", (PyCFunction)TextIOWrapper_readable, METH_NOARGS},
- {"writable", (PyCFunction)TextIOWrapper_writable, METH_NOARGS},
- {"isatty", (PyCFunction)TextIOWrapper_isatty, METH_NOARGS},
-
- {"seek", (PyCFunction)TextIOWrapper_seek, METH_VARARGS},
- {"tell", (PyCFunction)TextIOWrapper_tell, METH_NOARGS},
- {"truncate", (PyCFunction)TextIOWrapper_truncate, METH_VARARGS},
- {NULL, NULL}
-};
-
-static PyMemberDef TextIOWrapper_members[] = {
- {"encoding", T_OBJECT, offsetof(PyTextIOWrapperObject, encoding), READONLY},
- {"buffer", T_OBJECT, offsetof(PyTextIOWrapperObject, buffer), READONLY},
- {"line_buffering", T_BOOL, offsetof(PyTextIOWrapperObject, line_buffering), READONLY},
- {NULL}
-};
-
-static PyGetSetDef TextIOWrapper_getset[] = {
- {"name", (getter)TextIOWrapper_name_get, NULL, NULL},
- {"closed", (getter)TextIOWrapper_closed_get, NULL, NULL},
-/* {"mode", (getter)TextIOWrapper_mode_get, NULL, NULL},
-*/
- {"newlines", (getter)TextIOWrapper_newlines_get, NULL, NULL},
- {"_CHUNK_SIZE", (getter)TextIOWrapper_chunk_size_get,
- (setter)TextIOWrapper_chunk_size_set, NULL},
- {0}
-};
-
-PyTypeObject PyTextIOWrapper_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "_io.TextIOWrapper", /*tp_name*/
- sizeof(PyTextIOWrapperObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)TextIOWrapper_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tps_etattr*/
- 0, /*tp_compare */
- (reprfunc)TextIOWrapper_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 | Py_TPFLAGS_BASETYPE
- | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
- TextIOWrapper_doc, /* tp_doc */
- (traverseproc)TextIOWrapper_traverse, /* tp_traverse */
- (inquiry)TextIOWrapper_clear, /* tp_clear */
- 0, /* tp_richcompare */
- offsetof(PyTextIOWrapperObject, weakreflist), /*tp_weaklistoffset*/
- 0, /* tp_iter */
- (iternextfunc)TextIOWrapper_iternext, /* tp_iternext */
- TextIOWrapper_methods, /* tp_methods */
- TextIOWrapper_members, /* tp_members */
- TextIOWrapper_getset, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- offsetof(PyTextIOWrapperObject, dict), /*tp_dictoffset*/
- (initproc)TextIOWrapper_init, /* tp_init */
- 0, /* tp_alloc */
- PyType_GenericNew, /* tp_new */
-};
Modified: python/branches/py3k-short-float-repr/Modules/arraymodule.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/arraymodule.c	(original)
+++ python/branches/py3k-short-float-repr/Modules/arraymodule.c	Sun Apr 5 01:04:14 2009
@@ -1141,14 +1141,14 @@
 				> PY_SSIZE_T_MAX / Py_SIZE(array)) {
 			return PyErr_NoMemory();
 		}
-		result = Py_BuildValue("O(cy#)O", 
+		result = Py_BuildValue("O(Cy#)O",
 			Py_TYPE(array), 
 			array->ob_descr->typecode,
 			array->ob_item,
 			Py_SIZE(array) * array->ob_descr->itemsize,
 			dict);
 	} else {
-		result = Py_BuildValue("O(c)O", 
+		result = Py_BuildValue("O(C)O",
 			Py_TYPE(array), 
 			array->ob_descr->typecode,
 			dict);
Modified: python/branches/py3k-short-float-repr/Modules/cjkcodecs/multibytecodec.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/cjkcodecs/multibytecodec.c	(original)
+++ python/branches/py3k-short-float-repr/Modules/cjkcodecs/multibytecodec.c	Sun Apr 5 01:04:14 2009
@@ -506,7 +506,6 @@
 		outleft = (Py_ssize_t)(buf.outbuf_end - buf.outbuf);
 		r = codec->encode(state, codec->config, &buf.inbuf, inleft,
 				 &buf.outbuf, outleft, flags);
-		*data = buf.inbuf;
 		if ((r == 0) || (r == MBERR_TOOFEW && !(flags & MBENC_FLUSH)))
 			break;
 		else if (multibytecodec_encerror(codec, state, &buf, errors,r))
@@ -536,6 +535,7 @@
 		if (_PyBytes_Resize(&buf.outobj, finalsize) == -1)
 			goto errorexit;
 
+	*data = buf.inbuf;
 	Py_XDECREF(buf.excobj);
 	return buf.outobj;
 
Deleted: python/branches/py3k-short-float-repr/Modules/io.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/io.c	Sun Apr 5 01:04:14 2009
+++ (empty file)
@@ -1,760 +0,0 @@
-/*
- An implementation of the new I/O lib as defined by PEP 3116 - "New I/O"
- 
- Classes defined here: UnsupportedOperation, BlockingIOError.
- Functions defined here: open().
- 
- Mostly written by Amaury Forgeot d'Arc
-*/
-
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "structmember.h"
-#include "_iomodule.h"
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif /* HAVE_SYS_TYPES_H */
-
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif /* HAVE_SYS_STAT_H */
-
-
-/* Various interned strings */
-
-PyObject *_PyIO_str_close;
-PyObject *_PyIO_str_closed;
-PyObject *_PyIO_str_decode;
-PyObject *_PyIO_str_encode;
-PyObject *_PyIO_str_fileno;
-PyObject *_PyIO_str_flush;
-PyObject *_PyIO_str_getstate;
-PyObject *_PyIO_str_isatty;
-PyObject *_PyIO_str_newlines;
-PyObject *_PyIO_str_nl;
-PyObject *_PyIO_str_read;
-PyObject *_PyIO_str_read1;
-PyObject *_PyIO_str_readable;
-PyObject *_PyIO_str_readinto;
-PyObject *_PyIO_str_readline;
-PyObject *_PyIO_str_reset;
-PyObject *_PyIO_str_seek;
-PyObject *_PyIO_str_seekable;
-PyObject *_PyIO_str_tell;
-PyObject *_PyIO_str_truncate;
-PyObject *_PyIO_str_writable;
-PyObject *_PyIO_str_write;
-
-PyObject *_PyIO_empty_str;
-PyObject *_PyIO_empty_bytes;
-
-
-PyDoc_STRVAR(module_doc,
-"The io module provides the Python interfaces to stream handling. The\n"
-"builtin open function is defined in this module.\n"
-"\n"
-"At the top of the I/O hierarchy is the abstract base class IOBase. It\n"
-"defines the basic interface to a stream. Note, however, that there is no\n"
-"seperation between reading and writing to streams; implementations are\n"
-"allowed to throw an IOError if they do not support a given operation.\n"
-"\n"
-"Extending IOBase is RawIOBase which deals simply with the reading and\n"
-"writing of raw bytes to a stream. FileIO subc lasses RawIOBase to provide\n"
-"an interface to OS files.\n"
-"\n"
-"BufferedIOBase deals with buffering on a raw byte stream (RawIOBase). Its\n"
-"subclasses, BufferedWriter, BufferedReader, and BufferedRWPair buffer\n"
-"streams that are readable, writable, and both respectively.\n"
-"BufferedRandom provides a buffered interface to random access\n"
-"streams. BytesIO is a simple stream of in-memory bytes.\n"
-"\n"
-"Another IOBase subclass, TextIOBase, deals with the encoding and decoding\n"
-"of streams into text. TextIOWrapper, which extends it, is a buffered text\n"
-"interface to a buffered raw stream (`BufferedIOBase`). Finally, StringIO\n"
-"is a in-memory stream for text.\n"
-"\n"
-"Argument names are not part of the specification, and only the arguments\n"
-"of open() are intended to be used as keyword arguments.\n"
-"\n"
-"data:\n"
-"\n"
-"DEFAULT_BUFFER_SIZE\n"
-"\n"
-" An int containing the default buffer size used by the module's buffered\n"
-" I/O classes. open() uses the file's blksize (as obtained by os.stat) if\n"
-" possible.\n"
- );
-
-
-/*
- * BlockingIOError extends IOError
- */
-
-static int
-BlockingIOError_init(PyBlockingIOErrorObject *self, PyObject *args,
- PyObject *kwds)
-{
- PyObject *myerrno = NULL, *strerror = NULL;
- PyObject *baseargs = NULL;
- Py_ssize_t written = 0;
-
- assert(PyTuple_Check(args));
-
- self->written = 0;
- if (!PyArg_ParseTuple(args, "OO|n:BlockingIOError",
- &myerrno, &strerror, &written))
- return -1;
-
- baseargs = PyTuple_Pack(2, myerrno, strerror);
- if (baseargs == NULL)
- return -1;
- /* This will take care of initializing of myerrno and strerror members */
- if (((PyTypeObject *)PyExc_IOError)->tp_init(
- (PyObject *)self, baseargs, kwds) == -1) {
- Py_DECREF(baseargs);
- return -1;
- }
- Py_DECREF(baseargs);
-
- self->written = written;
- return 0;
-}
-
-static PyMemberDef BlockingIOError_members[] = {
- {"characters_written", T_PYSSIZET, offsetof(PyBlockingIOErrorObject, written), 0},
- {NULL} /* Sentinel */
-};
-
-static PyTypeObject _PyExc_BlockingIOError = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BlockingIOError", /*tp_name*/
- sizeof(PyBlockingIOErrorObject), /*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, /*tp_flags*/
- PyDoc_STR("Exception raised when I/O would block "
- "on a non-blocking I/O stream"), /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- 0, /* tp_methods */
- BlockingIOError_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)BlockingIOError_init, /* tp_init */
- 0, /* tp_alloc */
- 0, /* tp_new */
-};
-PyObject *PyExc_BlockingIOError = (PyObject *)&_PyExc_BlockingIOError;
-
-
-/*
- * The main open() function
- */
-PyDoc_STRVAR(open_doc,
-"Open file and return a stream. Raise IOError upon failure.\n"
-"\n"
-"file is either a text or byte string giving the name (and the path\n"
-"if the file isn't in the current working directory) of the file to\n"
-"be opened or an integer file descriptor of the file to be\n"
-"wrapped. (If a file descriptor is given, it is closed when the\n"
-"returned I/O object is closed, unless closefd is set to False.)\n"
-"\n"
-"mode is an optional string that specifies the mode in which the file\n"
-"is opened. It defaults to 'r' which means open for reading in text\n"
-"mode. Other common values are 'w' for writing (truncating the file if\n"
-"it already exists), and 'a' for appending (which on some Unix systems,\n"
-"means that all writes append to the end of the file regardless of the\n"
-"current seek position). In text mode, if encoding is not specified the\n"
-"encoding used is platform dependent. (For reading and writing raw\n"
-"bytes use binary mode and leave encoding unspecified.) The available\n"
-"modes are:\n"
-"\n"
-"========= ===============================================================\n"
-"Character Meaning\n"
-"--------- ---------------------------------------------------------------\n"
-"'r' open for reading (default)\n"
-"'w' open for writing, truncating the file first\n"
-"'a' open for writing, appending to the end of the file if it exists\n"
-"'b' binary mode\n"
-"'t' text mode (default)\n"
-"'+' open a disk file for updating (reading and writing)\n"
-"'U' universal newline mode (for backwards compatibility; unneeded\n"
-" for new code)\n"
-"========= ===============================================================\n"
-"\n"
-"The default mode is 'rt' (open for reading text). For binary random\n"
-"access, the mode 'w+b' opens and truncates the file to 0 bytes, while\n"
-"'r+b' opens the file without truncation.\n"
-"\n"
-"Python distinguishes between files opened in binary and text modes,\n"
-"even when the underlying operating system doesn't. Files opened in\n"
-"binary mode (appending 'b' to the mode argument) return contents as\n"
-"bytes objects without any decoding. In text mode (the default, or when\n"
-"'t' is appended to the mode argument), the contents of the file are\n"
-"returned as strings, the bytes having been first decoded using a\n"
-"platform-dependent encoding or using the specified encoding if given.\n"
-"\n"
-"buffering is an optional integer used to set the buffering policy. By\n"
-"default full buffering is on. Pass 0 to switch buffering off (only\n"
-"allowed in binary mode), 1 to set line buffering, and an integer > 1\n"
-"for full buffering.\n"
-"\n"
-"encoding is the name of the encoding used to decode or encode the\n"
-"file. This should only be used in text mode. The default encoding is\n"
-"platform dependent, but any encoding supported by Python can be\n"
-"passed. See the codecs module for the list of supported encodings.\n"
-"\n"
-"errors is an optional string that specifies how encoding errors are to\n"
-"be handled---this argument should not be used in binary mode. Pass\n"
-"'strict' to raise a ValueError exception if there is an encoding error\n"
-"(the default of None has the same effect), or pass 'ignore' to ignore\n"
-"errors. (Note that ignoring encoding errors can lead to data loss.)\n"
-"See the documentation for codecs.register for a list of the permitted\n"
-"encoding error strings.\n"
-"\n"
-"newline controls how universal newlines works (it only applies to text\n"
-"mode). It can be None, '', '\\n', '\\r', and '\\r\\n'. It works as\n"
-"follows:\n"
-"\n"
-"* On input, if newline is None, universal newlines mode is\n"
-" enabled. Lines in the input can end in '\\n', '\\r', or '\\r\\n', and\n"
-" these are translated into '\\n' before being returned to the\n"
-" caller. If it is '', universal newline mode is enabled, but line\n"
-" endings are returned to the caller untranslated. If it has any of\n"
-" the other legal values, input lines are only terminated by the given\n"
-" string, and the line ending is returned to the caller untranslated.\n"
-"\n"
-"* On output, if newline is None, any '\\n' characters written are\n"
-" translated to the system default line separator, os.linesep. If\n"
-" newline is '', no translation takes place. If newline is any of the\n"
-" other legal values, any '\\n' characters written are translated to\n"
-" the given string.\n"
-"\n"
-"If closefd is False, the underlying file descriptor will be kept open\n"
-"when the file is closed. This does not work when a file name is given\n"
-"and must be True in that case.\n"
-"\n"
-"open() returns a file object whose type depends on the mode, and\n"
-"through which the standard file operations such as reading and writing\n"
-"are performed. When open() is used to open a file in a text mode ('w',\n"
-"'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open\n"
-"a file in a binary mode, the returned class varies: in read binary\n"
-"mode, it returns a BufferedReader; in write binary and append binary\n"
-"modes, it returns a BufferedWriter, and in read/write mode, it returns\n"
-"a BufferedRandom.\n"
-"\n"
-"It is also possible to use a string or bytearray as a file for both\n"
-"reading and writing. For strings StringIO can be used like a file\n"
-"opened in a text mode, and for bytes a BytesIO can be used like a file\n"
-"opened in a binary mode.\n"
- );
-
-static PyObject *
-io_open(PyObject *self, PyObject *args, PyObject *kwds)
-{
- char *kwlist[] = {"file", "mode", "buffering",
- "encoding", "errors", "newline",
- "closefd", NULL};
- PyObject *file;
- char *mode = "r";
- int buffering = -1, closefd = 1;
- char *encoding = NULL, *errors = NULL, *newline = NULL;
- unsigned i;
-
- int reading = 0, writing = 0, appending = 0, updating = 0;
- int text = 0, binary = 0, universal = 0;
-
- char rawmode[5], *m;
- int line_buffering, isatty;
-
- PyObject *raw, *modeobj = NULL, *buffer = NULL, *wrapper = NULL;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|sizzzi:open", kwlist,
- &file, &mode, &buffering,
- &encoding, &errors, &newline,
- &closefd)) {
- return NULL;
- }
-
- if (!PyUnicode_Check(file) &&
-	!PyBytes_Check(file) &&
-	!PyNumber_Check(file)) {
- PyErr_Format(PyExc_TypeError, "invalid file: %R", file);
- return NULL;
- }
-
- /* Decode mode */
- for (i = 0; i < strlen(mode); i++) {
- char c = mode[i];
-
- switch (c) {
- case 'r':
- reading = 1;
- break;
- case 'w':
- writing = 1;
- break;
- case 'a':
- appending = 1;
- break;
- case '+':
- updating = 1;
- break;
- case 't':
- text = 1;
- break;
- case 'b':
- binary = 1;
- break;
- case 'U':
- universal = 1;
- reading = 1;
- break;
- default:
- goto invalid_mode;
- }
-
- /* c must not be duplicated */
- if (strchr(mode+i+1, c)) {
- invalid_mode:
- PyErr_Format(PyExc_ValueError, "invalid mode: '%s'", mode);
- return NULL;
- }
-
- }
-
- m = rawmode;
- if (reading) *(m++) = 'r';
- if (writing) *(m++) = 'w';
- if (appending) *(m++) = 'a';
- if (updating) *(m++) = '+';
- *m = '0円';
-
- /* Parameters validation */
- if (universal) {
- if (writing || appending) {
- PyErr_SetString(PyExc_ValueError,
- "can't use U and writing mode at once");
- return NULL;
- }
- reading = 1;
- }
-
- if (text && binary) {
- PyErr_SetString(PyExc_ValueError,
- "can't have text and binary mode at once");
- return NULL;
- }
-
- if (reading + writing + appending > 1) {
- PyErr_SetString(PyExc_ValueError,
- "must have exactly one of read/write/append mode");
- return NULL;
- }
-
- if (binary && encoding != NULL) {
- PyErr_SetString(PyExc_ValueError,
- "binary mode doesn't take an encoding argument");
- return NULL;
- }
-
- if (binary && errors != NULL) {
- PyErr_SetString(PyExc_ValueError,
- "binary mode doesn't take an errors argument");
- return NULL;
- }
-
- if (binary && newline != NULL) {
- PyErr_SetString(PyExc_ValueError,
- "binary mode doesn't take a newline argument");
- return NULL;
- }
-
- /* Create the Raw file stream */
- raw = PyObject_CallFunction((PyObject *)&PyFileIO_Type,
-				"Osi", file, rawmode, closefd);
- if (raw == NULL)
- return NULL;
-
- modeobj = PyUnicode_FromString(mode);
- if (modeobj == NULL)
- goto error;
-
- /* buffering */
- {
- PyObject *res = PyObject_CallMethod(raw, "isatty", NULL);
- if (res == NULL)
- goto error;
- isatty = PyLong_AsLong(res);
- Py_DECREF(res);
- if (isatty == -1 && PyErr_Occurred())
- goto error;
- }
-
- if (buffering == 1 || (buffering < 0 && isatty)) {
- buffering = -1;
- line_buffering = 1;
- }
- else
- line_buffering = 0;
-
- if (buffering < 0) {
- buffering = DEFAULT_BUFFER_SIZE;
-#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
- {
- struct stat st;
- long fileno;
- PyObject *res = PyObject_CallMethod(raw, "fileno", NULL);
- if (res == NULL)
- goto error;
-
- fileno = PyLong_AsLong(res);
- Py_DECREF(res);
- if (fileno == -1 && PyErr_Occurred())
- goto error;
-
- if (fstat(fileno, &st) >= 0)
- buffering = st.st_blksize;
- }
-#endif
- }
- if (buffering < 0) {
- PyErr_SetString(PyExc_ValueError,
- "invalid buffering size");
- goto error;
- }
-
- /* if not buffering, returns the raw file object */
- if (buffering == 0) {
- if (!binary) {
- PyErr_SetString(PyExc_ValueError,
- "can't have unbuffered text I/O");
- goto error;
- }
-
- Py_DECREF(modeobj);
- return raw;
- }
-
- /* wraps into a buffered file */
- {
- PyObject *Buffered_class;
-
- if (updating)
- Buffered_class = (PyObject *)&PyBufferedRandom_Type;
- else if (writing || appending)
- Buffered_class = (PyObject *)&PyBufferedWriter_Type;
- else if (reading)
- Buffered_class = (PyObject *)&PyBufferedReader_Type;
- else {
- PyErr_Format(PyExc_ValueError,
- "unknown mode: '%s'", mode);
- goto error;
- }
-
- buffer = PyObject_CallFunction(Buffered_class, "Oi", raw, buffering);
- }
- Py_CLEAR(raw);
- if (buffer == NULL)
- goto error;
-
-
- /* if binary, returns the buffered file */
- if (binary) {
- Py_DECREF(modeobj);
- return buffer;
- }
-
- /* wraps into a TextIOWrapper */
- wrapper = PyObject_CallFunction((PyObject *)&PyTextIOWrapper_Type,
-				 "Osssi",
-				 buffer,
-				 encoding, errors, newline,
-				 line_buffering);
- Py_CLEAR(buffer);
- if (wrapper == NULL)
- goto error;
-
- if (PyObject_SetAttrString(wrapper, "mode", modeobj) < 0)
- goto error;
- Py_DECREF(modeobj);
- return wrapper;
-
- error:
- Py_XDECREF(raw);
- Py_XDECREF(modeobj);
- Py_XDECREF(buffer);
- Py_XDECREF(wrapper);
- return NULL;
-}
-
-/*
- * Private helpers for the io module.
- */
-
-Py_off_t
-PyNumber_AsOff_t(PyObject *item, PyObject *err)
-{
- Py_off_t result;
- PyObject *runerr;
- PyObject *value = PyNumber_Index(item);
- if (value == NULL)
- return -1;
-
- /* We're done if PyLong_AsSsize_t() returns without error. */
- result = PyLong_AsOff_t(value);
- if (result != -1 || !(runerr = PyErr_Occurred()))
- goto finish;
-
- /* Error handling code -- only manage OverflowError differently */
- if (!PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError))
- goto finish;
-
- PyErr_Clear();
- /* 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
- zero is determined by the sign of ob_size
- */
- if (_PyLong_Sign(value) < 0)
- result = PY_OFF_T_MIN;
- else
- result = PY_OFF_T_MAX;
- }
- else {
- /* Otherwise replace the error with caller's error object. */
- PyErr_Format(err,
- "cannot fit '%.200s' into an offset-sized integer",
- item->ob_type->tp_name);
- }
-
- finish:
- Py_DECREF(value);
- return result;
-}
-
-static int
-iomodule_traverse(PyObject *mod, visitproc visit, void *arg) {
- _PyIO_State *state = IO_MOD_STATE(mod);
- if (!state->initialized)
- return 0;
- Py_VISIT(state->os_module);
- if (state->locale_module != NULL) {
- Py_VISIT(state->locale_module);
- }
- Py_VISIT(state->unsupported_operation);
- return 0;
-}
-
-static int
-iomodule_clear(PyObject *mod) {
- _PyIO_State *state = IO_MOD_STATE(mod);
- if (!state->initialized)
- return 0;
- Py_CLEAR(state->os_module);
- if (state->locale_module != NULL)
- Py_CLEAR(state->locale_module);
- Py_CLEAR(state->unsupported_operation);
- return 0;
-}
-
-static void
-iomodule_free(PyObject *mod) {
- iomodule_clear(mod);
-}
-
-/*
- * Module definition
- */
-
-static PyMethodDef module_methods[] = {
- {"open", (PyCFunction)io_open, METH_VARARGS|METH_KEYWORDS, open_doc},
- {NULL, NULL}
-};
-
-struct PyModuleDef _PyIO_Module = {
- PyModuleDef_HEAD_INIT,
- "io",
- module_doc,
- sizeof(_PyIO_State),
- module_methods,
- NULL,
- iomodule_traverse,
- iomodule_clear,
- (freefunc)iomodule_free,
-};
-
-PyMODINIT_FUNC
-PyInit__io(void)
-{
- PyObject *m = PyModule_Create(&_PyIO_Module);
- _PyIO_State *state = NULL;
- if (m == NULL)
- return NULL;
- state = IO_MOD_STATE(m);
- state->initialized = 0;
-
- /* put os in the module state */
- state->os_module = PyImport_ImportModule("os");
- if (state->os_module == NULL)
- goto fail;
-
-#define ADD_TYPE(type, name) \
- if (PyType_Ready(type) < 0) \
- goto fail; \
- Py_INCREF(type); \
- if (PyModule_AddObject(m, name, (PyObject *)type) < 0) { \
- Py_DECREF(type); \
- goto fail; \
- }
-
- /* DEFAULT_BUFFER_SIZE */
- if (PyModule_AddIntMacro(m, DEFAULT_BUFFER_SIZE) < 0)
- goto fail;
-
- /* UnsupportedOperation inherits from ValueError and IOError */
- state->unsupported_operation = PyObject_CallFunction(
- (PyObject *)&PyType_Type, "s(OO){}",
- "UnsupportedOperation", PyExc_ValueError, PyExc_IOError);
- if (state->unsupported_operation == NULL)
- goto fail;
- Py_INCREF(state->unsupported_operation);
- if (PyModule_AddObject(m, "UnsupportedOperation",
- state->unsupported_operation) < 0)
- goto fail;
-
- /* BlockingIOError */
- _PyExc_BlockingIOError.tp_base = (PyTypeObject *) PyExc_IOError;
- ADD_TYPE(&_PyExc_BlockingIOError, "BlockingIOError");
-
- /* Concrete base types of the IO ABCs.
- (the ABCs themselves are declared through inheritance in io.py)
- */
- ADD_TYPE(&PyIOBase_Type, "_IOBase");
- ADD_TYPE(&PyRawIOBase_Type, "_RawIOBase");
- ADD_TYPE(&PyBufferedIOBase_Type, "_BufferedIOBase");
- ADD_TYPE(&PyTextIOBase_Type, "_TextIOBase");
-
- /* Implementation of concrete IO objects. */
- /* FileIO */
- PyFileIO_Type.tp_base = &PyRawIOBase_Type;
- ADD_TYPE(&PyFileIO_Type, "FileIO");
-
- /* BytesIO */
- PyBytesIO_Type.tp_base = &PyBufferedIOBase_Type;
- ADD_TYPE(&PyBytesIO_Type, "BytesIO");
-
- /* StringIO */
- PyStringIO_Type.tp_base = &PyTextIOBase_Type;
- ADD_TYPE(&PyStringIO_Type, "StringIO");
-
- /* BufferedReader */
- PyBufferedReader_Type.tp_base = &PyBufferedIOBase_Type;
- ADD_TYPE(&PyBufferedReader_Type, "BufferedReader");
-
- /* BufferedWriter */
- PyBufferedWriter_Type.tp_base = &PyBufferedIOBase_Type;
- ADD_TYPE(&PyBufferedWriter_Type, "BufferedWriter");
-
- /* BufferedRWPair */
- PyBufferedRWPair_Type.tp_base = &PyBufferedIOBase_Type;
- ADD_TYPE(&PyBufferedRWPair_Type, "BufferedRWPair");
-
- /* BufferedRandom */
- PyBufferedRandom_Type.tp_base = &PyBufferedIOBase_Type;
- ADD_TYPE(&PyBufferedRandom_Type, "BufferedRandom");
-
- /* TextIOWrapper */
- PyTextIOWrapper_Type.tp_base = &PyTextIOBase_Type;
- ADD_TYPE(&PyTextIOWrapper_Type, "TextIOWrapper");
-
- /* IncrementalNewlineDecoder */
- ADD_TYPE(&PyIncrementalNewlineDecoder_Type, "IncrementalNewlineDecoder");
-
- /* Interned strings */
- if (!(_PyIO_str_close = PyUnicode_InternFromString("close")))
- goto fail;
- if (!(_PyIO_str_closed = PyUnicode_InternFromString("closed")))
- goto fail;
- if (!(_PyIO_str_decode = PyUnicode_InternFromString("decode")))
- goto fail;
- if (!(_PyIO_str_encode = PyUnicode_InternFromString("encode")))
- goto fail;
- if (!(_PyIO_str_fileno = PyUnicode_InternFromString("fileno")))
- goto fail;
- if (!(_PyIO_str_flush = PyUnicode_InternFromString("flush")))
- goto fail;
- if (!(_PyIO_str_getstate = PyUnicode_InternFromString("getstate")))
- goto fail;
- if (!(_PyIO_str_isatty = PyUnicode_InternFromString("isatty")))
- goto fail;
- if (!(_PyIO_str_newlines = PyUnicode_InternFromString("newlines")))
- goto fail;
- if (!(_PyIO_str_nl = PyUnicode_InternFromString("\n")))
- goto fail;
- if (!(_PyIO_str_read = PyUnicode_InternFromString("read")))
- goto fail;
- if (!(_PyIO_str_read1 = PyUnicode_InternFromString("read1")))
- goto fail;
- if (!(_PyIO_str_readable = PyUnicode_InternFromString("readable")))
- goto fail;
- if (!(_PyIO_str_readinto = PyUnicode_InternFromString("readinto")))
- goto fail;
- if (!(_PyIO_str_readline = PyUnicode_InternFromString("readline")))
- goto fail;
- if (!(_PyIO_str_reset = PyUnicode_InternFromString("reset")))
- goto fail;
- if (!(_PyIO_str_seek = PyUnicode_InternFromString("seek")))
- goto fail;
- if (!(_PyIO_str_seekable = PyUnicode_InternFromString("seekable")))
- goto fail;
- if (!(_PyIO_str_tell = PyUnicode_InternFromString("tell")))
- goto fail;
- if (!(_PyIO_str_truncate = PyUnicode_InternFromString("truncate")))
- goto fail;
- if (!(_PyIO_str_write = PyUnicode_InternFromString("write")))
- goto fail;
- if (!(_PyIO_str_writable = PyUnicode_InternFromString("writable")))
- goto fail;
- 
- if (!(_PyIO_empty_str = PyUnicode_FromStringAndSize(NULL, 0)))
- goto fail;
- if (!(_PyIO_empty_bytes = PyBytes_FromStringAndSize(NULL, 0)))
- goto fail;
-
- state->initialized = 1;
-
- return m;
-
- fail:
- Py_XDECREF(state->os_module);
- Py_XDECREF(state->unsupported_operation);
- Py_DECREF(m);
- return NULL;
-}
Modified: python/branches/py3k-short-float-repr/Modules/mmapmodule.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/mmapmodule.c	(original)
+++ python/branches/py3k-short-float-repr/Modules/mmapmodule.c	Sun Apr 5 01:04:14 2009
@@ -204,7 +204,7 @@
 	if (self->pos < self->size) {
 	 char value = self->data[self->pos];
 		self->pos += 1;
-		return Py_BuildValue("c", value);
+		return Py_BuildValue("b", value);
 	} else {
 		PyErr_SetString(PyExc_ValueError, "read byte out of range");
 		return NULL;
@@ -264,7 +264,7 @@
 	Py_ssize_t len;
 
 	CHECK_VALID(NULL);
-	if (!PyArg_ParseTuple(args, reverse ? "s#|nn:rfind" : "s#|nn:find",
+	if (!PyArg_ParseTuple(args, reverse ? "y#|nn:rfind" : "y#|nn:find",
 			 &needle, &len, &start, &end)) {
 		return NULL;
 	} else {
@@ -348,7 +348,7 @@
 	char *data;
 
 	CHECK_VALID(NULL);
-	if (!PyArg_ParseTuple(args, "s#:write", &data, &length))
+	if (!PyArg_ParseTuple(args, "y#:write", &data, &length))
 		return(NULL);
 
 	if (!is_writable(self))
@@ -371,7 +371,7 @@
 	char value;
 
 	CHECK_VALID(NULL);
-	if (!PyArg_ParseTuple(args, "c:write_byte", &value))
+	if (!PyArg_ParseTuple(args, "b:write_byte", &value))
 		return(NULL);
 
 	if (!is_writable(self))
@@ -520,7 +520,11 @@
 #ifdef MREMAP_MAYMOVE
 		newmap = mremap(self->data, self->size, new_size, MREMAP_MAYMOVE);
 #else
-		newmap = mremap(self->data, self->size, new_size, 0);
+		#if defined(__NetBSD__)
+			newmap = mremap(self->data, self->size, self->data, new_size, 0);
+		#else
+			newmap = mremap(self->data, self->size, new_size, 0);
+		#endif /* __NetBSD__ */
 #endif
 		if (newmap == (void *)-1)
 		{
@@ -623,10 +627,8 @@
 		return NULL;
 	} else {
 		/* bounds check the values */
-		if (/* end of source after end of data?? */
-			((src+count) > self->size)
-			/* dest will fit? */
-			|| (dest+count > self->size)) {
+		unsigned long pos = src > dest ? src : dest;
+		if (self->size < pos || count > self->size - pos) {
 			PyErr_SetString(PyExc_ValueError,
 					"source or destination out of range");
 			return NULL;
Modified: python/branches/py3k-short-float-repr/Modules/socketmodule.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/socketmodule.c	(original)
+++ python/branches/py3k-short-float-repr/Modules/socketmodule.c	Sun Apr 5 01:04:14 2009
@@ -382,7 +382,7 @@
 #define SOCKETCLOSE close
 #endif
 
-#if defined(HAVE_BLUETOOTH_H) || defined(HAVE_BLUETOOTH_BLUETOOTH_H)
+#if defined(HAVE_BLUETOOTH_H) || defined(HAVE_BLUETOOTH_BLUETOOTH_H) && !defined(__NetBSD__)
 #define USE_BLUETOOTH 1
 #if defined(__FreeBSD__)
 #define BTPROTO_L2CAP BLUETOOTH_PROTO_L2CAP
Modified: python/branches/py3k-short-float-repr/Objects/bytearrayobject.c
==============================================================================
--- python/branches/py3k-short-float-repr/Objects/bytearrayobject.c	(original)
+++ python/branches/py3k-short-float-repr/Objects/bytearrayobject.c	Sun Apr 5 01:04:14 2009
@@ -411,18 +411,18 @@
 }
 else {
 char *source_buf = PyByteArray_AS_STRING(self);
- char *result_buf = (char *)PyMem_Malloc(slicelength);
+ char *result_buf;
 PyObject *result;
 
- if (result_buf == NULL)
- return PyErr_NoMemory();
+ result = PyByteArray_FromStringAndSize(NULL, slicelength);
+ if (result == NULL)
+ return NULL;
 
+ result_buf = PyByteArray_AS_STRING(result);
 for (cur = start, i = 0; i < slicelength;
 cur += step, i++) {
 result_buf[i] = source_buf[cur];
 }
- result = PyByteArray_FromStringAndSize(result_buf, slicelength);
- PyMem_Free(result_buf);
 return result;
 }
 }
Modified: python/branches/py3k-short-float-repr/Objects/bytesobject.c
==============================================================================
--- python/branches/py3k-short-float-repr/Objects/bytesobject.c	(original)
+++ python/branches/py3k-short-float-repr/Objects/bytesobject.c	Sun Apr 5 01:04:14 2009
@@ -583,6 +583,7 @@
 #include "stringlib/transmogrify.h"
 
 #define _Py_InsertThousandsGrouping _PyBytes_InsertThousandsGrouping
+#define _Py_InsertThousandsGroupingLocale _PyBytes_InsertThousandsGroupingLocale
 #include "stringlib/localeutil.h"
 
 PyObject *
@@ -951,19 +952,17 @@
 				slicelength);
 		}
 		else {
-			source_buf = PyBytes_AsString((PyObject*)self);
-			result_buf = (char *)PyMem_Malloc(slicelength);
-			if (result_buf == NULL)
-				return PyErr_NoMemory();
+			source_buf = PyBytes_AS_STRING(self);
+			result = PyBytes_FromStringAndSize(NULL, slicelength);
+			if (result == NULL)
+				return NULL;
 
+			result_buf = PyBytes_AS_STRING(result);
 			for (cur = start, i = 0; i < slicelength;
 			 cur += step, i++) {
 				result_buf[i] = source_buf[cur];
 			}
 
-			result = PyBytes_FromStringAndSize(result_buf,
-							 slicelength);
-			PyMem_Free(result_buf);
 			return result;
 		}
 	}
Modified: python/branches/py3k-short-float-repr/Objects/exceptions.c
==============================================================================
--- python/branches/py3k-short-float-repr/Objects/exceptions.c	(original)
+++ python/branches/py3k-short-float-repr/Objects/exceptions.c	Sun Apr 5 01:04:14 2009
@@ -250,11 +250,67 @@
 return 0;
 }
 
+static PyObject *
+BaseException_get_context(PyObject *self) {
+ PyObject *res = PyException_GetContext(self);
+ if (res) return res; /* new reference already returned above */
+ Py_RETURN_NONE;
+}
+
+static int
+BaseException_set_context(PyObject *self, PyObject *arg) {
+ if (arg == NULL) {
+ PyErr_SetString(PyExc_TypeError, "__context__ may not be deleted");
+ return -1;
+ } else if (arg == Py_None) {
+ arg = NULL;
+ } else if (!PyExceptionInstance_Check(arg)) {
+ PyErr_SetString(PyExc_TypeError, "exception context must be None "
+ "or derive from BaseException");
+ return -1;
+ } else {
+ /* PyException_SetContext steals this reference */
+ Py_INCREF(arg);
+ } 
+ PyException_SetContext(self, arg);
+ return 0;
+}
+
+static PyObject *
+BaseException_get_cause(PyObject *self) {
+ PyObject *res = PyException_GetCause(self);
+ if (res) return res; /* new reference already returned above */
+ Py_RETURN_NONE;
+}
+
+static int
+BaseException_set_cause(PyObject *self, PyObject *arg) {
+ if (arg == NULL) {
+ PyErr_SetString(PyExc_TypeError, "__cause__ may not be deleted");
+ return -1;
+ } else if (arg == Py_None) {
+ arg = NULL;
+ } else if (!PyExceptionInstance_Check(arg)) {
+ PyErr_SetString(PyExc_TypeError, "exception cause must be None "
+ "or derive from BaseException");
+ return -1;
+ } else {
+ /* PyException_SetCause steals this reference */
+ Py_INCREF(arg);
+ } 
+ PyException_SetCause(self, arg);
+ return 0;
+}
+
 
 static PyGetSetDef BaseException_getset[] = {
 {"__dict__", (getter)BaseException_get_dict, (setter)BaseException_set_dict},
 {"args", (getter)BaseException_get_args, (setter)BaseException_set_args},
 {"__traceback__", (getter)BaseException_get_tb, (setter)BaseException_set_tb},
+ {"__context__", (getter)BaseException_get_context,
+ (setter)BaseException_set_context, PyDoc_STR("exception context")},
+ {"__cause__", (getter)BaseException_get_cause,
+ (setter)BaseException_set_cause, PyDoc_STR("exception cause")},
 {NULL},
 };
 
@@ -303,14 +359,6 @@
 }
 
 
-static PyMemberDef BaseException_members[] = {
- {"__context__", T_OBJECT, offsetof(PyBaseExceptionObject, context), 0,
- PyDoc_STR("exception context")},
- {"__cause__", T_OBJECT, offsetof(PyBaseExceptionObject, cause), 0,
- PyDoc_STR("exception cause")},
- {NULL} /* Sentinel */
-};
-
 static PyTypeObject _PyExc_BaseException = {
 PyVarObject_HEAD_INIT(NULL, 0)
 "BaseException", /*tp_name*/
@@ -341,7 +389,7 @@
 0, /* tp_iter */
 0, /* tp_iternext */
 BaseException_methods, /* tp_methods */
- BaseException_members, /* tp_members */
+ 0, /* tp_members */
 BaseException_getset, /* tp_getset */
 0, /* tp_base */
 0, /* tp_dict */
Modified: python/branches/py3k-short-float-repr/Objects/longobject.c
==============================================================================
--- python/branches/py3k-short-float-repr/Objects/longobject.c	(original)
+++ python/branches/py3k-short-float-repr/Objects/longobject.c	Sun Apr 5 01:04:14 2009
@@ -4092,8 +4092,10 @@
 	int_info = PyStructSequence_New(&Int_InfoType);
 	if (int_info == NULL)
 		return NULL;
-	PyStructSequence_SET_ITEM(int_info, field++, PyLong_FromLong(PyLong_SHIFT));
-	PyStructSequence_SET_ITEM(int_info, field++, PyLong_FromLong(sizeof(digit)));
+	PyStructSequence_SET_ITEM(int_info, field++,
+				 PyLong_FromLong(PyLong_SHIFT));
+	PyStructSequence_SET_ITEM(int_info, field++,
+				 PyLong_FromLong(sizeof(digit)));
 	if (PyErr_Occurred()) {
 		Py_CLEAR(int_info);
 		return NULL;
Modified: python/branches/py3k-short-float-repr/Objects/stringlib/formatter.h
==============================================================================
--- python/branches/py3k-short-float-repr/Objects/stringlib/formatter.h	(original)
+++ python/branches/py3k-short-float-repr/Objects/stringlib/formatter.h	Sun Apr 5 01:04:14 2009
@@ -120,6 +120,7 @@
 int alternate;
 STRINGLIB_CHAR sign;
 Py_ssize_t width;
+ int thousands_separators;
 Py_ssize_t precision;
 STRINGLIB_CHAR type;
 } InternalFormatSpec;
@@ -132,7 +133,7 @@
 */
 static int
 parse_internal_render_format_spec(STRINGLIB_CHAR *format_spec,
-				 Py_ssize_t format_spec_len,
+ Py_ssize_t format_spec_len,
 InternalFormatSpec *format,
 char default_type)
 {
@@ -149,6 +150,7 @@
 format->alternate = 0;
 format->sign = '0円';
 format->width = -1;
+ format->thousands_separators = 0;
 format->precision = -1;
 format->type = default_type;
 
@@ -178,8 +180,8 @@
 /* If the next character is #, we're in alternate mode. This only
 applies to integers. */
 if (end-ptr >= 1 && ptr[0] == '#') {
-	format->alternate = 1;
-	++ptr;
+ format->alternate = 1;
+ ++ptr;
 }
 
 /* The special case for 0-padding (backwards compat) */
@@ -201,6 +203,12 @@
 format->width = -1;
 }
 
+ /* Comma signifies add thousands separators */
+ if (end-ptr && ptr[0] == ',') {
+ format->thousands_separators = 1;
+ ++ptr;
+ }
+
 /* Parse field precision */
 if (end-ptr && ptr[0] == '.') {
 ++ptr;
@@ -230,6 +238,11 @@
 ++ptr;
 }
 
+ if (format->type == 'n' && format->thousands_separators) {
+ PyErr_Format(PyExc_ValueError, "Cannot specify ',' with 'n'.");
+ return 0;
+ }
+
 return 1;
 }
 
@@ -259,8 +272,8 @@
 and more efficient enough to justify a little obfuscation? */
 static void
 calc_number_widths(NumberFieldWidths *spec, STRINGLIB_CHAR actual_sign,
-		 Py_ssize_t n_prefix, Py_ssize_t n_digits,
-		 const InternalFormatSpec *format)
+ Py_ssize_t n_prefix, Py_ssize_t n_digits,
+ const InternalFormatSpec *format)
 {
 spec->n_lpadding = 0;
 spec->n_prefix = 0;
@@ -327,7 +340,7 @@
 else {
 /* see if any padding is needed */
 if (spec->n_lsign + n_digits + spec->n_rsign +
-	 spec->n_prefix >= format->width) {
+ spec->n_prefix >= format->width) {
 /* no padding needed, we're already bigger than the
 requested width */
 }
@@ -335,8 +348,8 @@
 /* determine which of left, space, or right padding is
 needed */
 Py_ssize_t padding = format->width -
-		 (spec->n_lsign + spec->n_prefix +
-				 n_digits + spec->n_rsign);
+ (spec->n_lsign + spec->n_prefix +
+ n_digits + spec->n_rsign);
 if (format->align == '<')
 spec->n_rpadding = padding;
 else if (format->align == '>')
@@ -352,7 +365,7 @@
 }
 }
 spec->n_total = spec->n_lpadding + spec->n_lsign + spec->n_prefix +
-	 spec->n_spadding + n_digits + spec->n_rsign + spec->n_rpadding;
+ spec->n_spadding + n_digits + spec->n_rsign + spec->n_rpadding;
 }
 
 /* fill in the non-digit parts of a numbers's string representation,
@@ -360,8 +373,8 @@
 where the digits go. */
 static STRINGLIB_CHAR *
 fill_non_digits(STRINGLIB_CHAR *p_buf, const NumberFieldWidths *spec,
-		STRINGLIB_CHAR *prefix, Py_ssize_t n_digits,
-		STRINGLIB_CHAR fill_char)
+ STRINGLIB_CHAR *prefix, Py_ssize_t n_digits,
+ STRINGLIB_CHAR fill_char)
 {
 STRINGLIB_CHAR *p_digits;
 
@@ -373,10 +386,10 @@
 *p_buf++ = spec->lsign;
 }
 if (spec->n_prefix) {
-	memmove(p_buf,
-		prefix,
-		spec->n_prefix * sizeof(STRINGLIB_CHAR));
-	p_buf += spec->n_prefix;
+ memmove(p_buf,
+ prefix,
+ spec->n_prefix * sizeof(STRINGLIB_CHAR));
+ p_buf += spec->n_prefix;
 }
 if (spec->n_spadding) {
 STRINGLIB_FILL(p_buf, fill_char, spec->n_spadding);
@@ -420,7 +433,7 @@
 if (format->alternate) {
 PyErr_SetString(PyExc_ValueError,
 "Alternate form (#) not allowed in string format "
-			"specifier");
+ "specifier");
 goto done;
 }
 
@@ -504,7 +517,7 @@
 
 static PyObject *
 format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format,
-			 IntOrLongToString tostring)
+ IntOrLongToString tostring)
 {
 PyObject *result = NULL;
 PyObject *tmp = NULL;
@@ -516,8 +529,8 @@
 string */
 Py_ssize_t n_leading_chars;
 Py_ssize_t n_grouping_chars = 0; /* Count of additional chars to
-					allocate, used for 'n'
-					formatting. */
+ allocate, used for 'n'
+ formatting. */
 Py_ssize_t n_prefix = 0; /* Count of prefix chars, (e.g., '0x') */
 STRINGLIB_CHAR *prefix = NULL;
 NumberFieldWidths spec;
@@ -562,31 +575,31 @@
 goto done;
 }
 #endif
-	numeric_char = (STRINGLIB_CHAR)x;
-	pnumeric_chars = &numeric_char;
+ numeric_char = (STRINGLIB_CHAR)x;
+ pnumeric_chars = &numeric_char;
 n_digits = 1;
 }
 else {
 int base;
-	int leading_chars_to_skip = 0; /* Number of characters added by
-				 PyNumber_ToBase that we want to
-				 skip over. */
+ int leading_chars_to_skip = 0; /* 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;
-	 leading_chars_to_skip = 2; /* 0b */
+ leading_chars_to_skip = 2; /* 0b */
 break;
 case 'o':
 base = 8;
-	 leading_chars_to_skip = 2; /* 0o */
+ leading_chars_to_skip = 2; /* 0o */
 break;
 case 'x':
 case 'X':
 base = 16;
-	 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':
@@ -595,52 +608,57 @@
 break;
 }
 
-	/* The number of prefix chars is the same as the leading
-	 chars to skip */
-	if (format->alternate)
-	 n_prefix = leading_chars_to_skip;
+ /* The number of prefix chars is the same as the leading
+ chars to skip */
+ if (format->alternate)
+ n_prefix = leading_chars_to_skip;
 
 /* Do the hard part, converting to a string in a given base */
-	tmp = tostring(value, base);
+ tmp = tostring(value, base);
 if (tmp == NULL)
 goto done;
 
-	pnumeric_chars = STRINGLIB_STR(tmp);
+ pnumeric_chars = STRINGLIB_STR(tmp);
 n_digits = STRINGLIB_LEN(tmp);
 
-	prefix = pnumeric_chars;
+ prefix = pnumeric_chars;
 
-	/* 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. */
+ /* 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
 and skip it */
 sign = pnumeric_chars[0];
 if (sign == '-') {
-	 ++prefix;
-	 ++leading_chars_to_skip;
+ ++prefix;
+ ++leading_chars_to_skip;
 }
 
-	/* Skip over the leading chars (0x, 0b, etc.) */
-	n_digits -= leading_chars_to_skip;
-	pnumeric_chars += leading_chars_to_skip;
+ /* Skip over the leading chars (0x, 0b, etc.) */
+ n_digits -= leading_chars_to_skip;
+ pnumeric_chars += leading_chars_to_skip;
 }
 
 if (format->type == 'n')
-	 /* Compute how many additional chars we need to allocate
-	 to hold the thousands grouping. */
-	 STRINGLIB_GROUPING(NULL, n_digits, n_digits,
-			 0, &n_grouping_chars, 0);
+ /* Compute how many additional chars we need to allocate
+ to hold the thousands grouping. */
+ STRINGLIB_GROUPING_LOCALE(NULL, n_digits, n_digits,
+ 0, &n_grouping_chars, 0);
+ if (format->thousands_separators)
+ /* Compute how many additional chars we need to allocate
+ to hold the thousands grouping. */
+ STRINGLIB_GROUPING(NULL, n_digits, n_digits,
+ 0, &n_grouping_chars, 0, "3円", ",");
 
 /* Calculate the widths of the various leading and trailing parts */
 calc_number_widths(&spec, sign, n_prefix, n_digits + n_grouping_chars,
-		 format);
+ format);
 
 /* Allocate a new string to hold the result */
 result = STRINGLIB_NEW(NULL, spec.n_total);
 if (!result)
-	goto done;
+ goto done;
 p = STRINGLIB_STR(result);
 
 /* XXX There is too much magic here regarding the internals of
@@ -651,44 +669,55 @@
 
 /* Fill in the digit parts */
 n_leading_chars = spec.n_lpadding + spec.n_lsign +
-	 spec.n_prefix + spec.n_spadding;
+ spec.n_prefix + spec.n_spadding;
 memmove(p + n_leading_chars,
-	 pnumeric_chars,
-	 n_digits * sizeof(STRINGLIB_CHAR));
+ pnumeric_chars,
+ n_digits * sizeof(STRINGLIB_CHAR));
 
 /* If type is 'X', convert the filled in digits 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]);
+ Py_ssize_t t;
+ for (t = 0; t < n_digits; ++t)
+ p[t + n_leading_chars] = STRINGLIB_TOUPPER(p[t + n_leading_chars]);
 }
 
 /* Insert the grouping, if any, after the uppercasing of the digits, so
 we can ensure that grouping chars won't be affected. */
 if (n_grouping_chars) {
-	 /* We know this can't fail, since we've already
-	 reserved enough space. */
-	 STRINGLIB_CHAR *pstart = p + n_leading_chars;
+ /* We know this can't fail, since we've already
+ reserved enough space. */
+ STRINGLIB_CHAR *pstart = p + n_leading_chars;
+#ifndef NDEBUG
+ int r;
+#endif
+ if (format->type == 'n')
+#ifndef NDEBUG
+ r =
+#endif
+ STRINGLIB_GROUPING_LOCALE(pstart, n_digits, n_digits,
+ spec.n_total+n_grouping_chars-n_leading_chars,
+ NULL, 0);
+ else
 #ifndef NDEBUG
-	 int r =
+ r =
 #endif
-		STRINGLIB_GROUPING(pstart, n_digits, n_digits,
-			 spec.n_total+n_grouping_chars-n_leading_chars,
-			 NULL, 0);
-	 assert(r);
+ STRINGLIB_GROUPING(pstart, n_digits, n_digits,
+ spec.n_total+n_grouping_chars-n_leading_chars,
+ NULL, 0, "3円", ",");
+ assert(r);
 }
 
 /* Fill in the non-digit parts (padding, sign, etc.) */
 fill_non_digits(p, &spec, prefix, n_digits + n_grouping_chars,
-		 format->fill_char == '0円' ? ' ' : format->fill_char);
+ format->fill_char == '0円' ? ' ' : format->fill_char);
 
 /* If type is 'X', uppercase the prefix. This has to be done after the
 prefix is filled in by fill_non_digits */
 if (format->type == 'X') {
-	Py_ssize_t t;
-	for (t = 0; t < n_prefix; ++t)
-	 p[t + spec.n_lpadding + spec.n_lsign] =
-		 STRINGLIB_TOUPPER(p[t + spec.n_lpadding + spec.n_lsign]);
+ Py_ssize_t t;
+ for (t = 0; t < n_prefix; ++t)
+ p[t + spec.n_lpadding + spec.n_lsign] =
+ STRINGLIB_TOUPPER(p[t + spec.n_lpadding + spec.n_lsign]);
 }
 
 
@@ -723,7 +752,7 @@
 /* much of this is taken from unicodeobject.c */
 static PyObject *
 format_float_internal(PyObject *value,
-		 const InternalFormatSpec *format)
+ const InternalFormatSpec *format)
 {
 /* fmt = '%.' + `prec` + `type` + '%%'
 worst case length = 2 + 10 (len of INT_MAX) + 1 + 2 = 15 (use 20)*/
@@ -765,7 +794,7 @@
 if (format->alternate) {
 PyErr_SetString(PyExc_ValueError,
 "Alternate form (#) not allowed in float format "
-			"specifier");
+ "specifier");
 goto done;
 }
 
@@ -796,7 +825,7 @@
 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);
+ (char)type);
 
 /* do the actual formatting */
 PyOS_ascii_formatd(charbuf, sizeof(charbuf), fmt, x);
@@ -838,11 +867,11 @@
 
 /* Fill in the non-digit parts (padding, sign, etc.) */
 fill_non_digits(STRINGLIB_STR(result), &spec, NULL, n_digits,
-		 format->fill_char == '0円' ? ' ' : format->fill_char);
+ 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),
+ (spec.n_lpadding + spec.n_lsign + spec.n_spadding),
 p,
 n_digits * sizeof(STRINGLIB_CHAR));
 
@@ -856,8 +885,8 @@
 /************************************************************************/
 PyObject *
 FORMAT_STRING(PyObject *obj,
-	 STRINGLIB_CHAR *format_spec,
-	 Py_ssize_t format_spec_len)
+ STRINGLIB_CHAR *format_spec,
+ Py_ssize_t format_spec_len)
 {
 InternalFormatSpec format;
 PyObject *result = NULL;
@@ -871,7 +900,7 @@
 
 /* parse the format_spec */
 if (!parse_internal_render_format_spec(format_spec, format_spec_len,
-					 &format, 's'))
+ &format, 's'))
 goto done;
 
 /* type conversion? */
@@ -893,9 +922,9 @@
 #if defined FORMAT_LONG || defined FORMAT_INT
 static PyObject*
 format_int_or_long(PyObject* obj,
-		 STRINGLIB_CHAR *format_spec,
-		 Py_ssize_t format_spec_len,
-		 IntOrLongToString tostring)
+ STRINGLIB_CHAR *format_spec,
+ Py_ssize_t format_spec_len,
+ IntOrLongToString tostring)
 {
 PyObject *result = NULL;
 PyObject *tmp = NULL;
@@ -910,8 +939,8 @@
 
 /* parse the format_spec */
 if (!parse_internal_render_format_spec(format_spec,
-					 format_spec_len,
-					 &format, 'd'))
+ format_spec_len,
+ &format, 'd'))
 goto done;
 
 /* type conversion? */
@@ -924,8 +953,8 @@
 case 'X':
 case 'n':
 /* no type conversion needed, already an int (or long). do
-	 the formatting */
-	 result = format_int_or_long_internal(obj, &format, tostring);
+ the formatting */
+ result = format_int_or_long_internal(obj, &format, tostring);
 break;
 
 case 'e':
@@ -974,11 +1003,11 @@
 
 PyObject *
 FORMAT_LONG(PyObject *obj,
-	 STRINGLIB_CHAR *format_spec,
-	 Py_ssize_t format_spec_len)
+ STRINGLIB_CHAR *format_spec,
+ Py_ssize_t format_spec_len)
 {
 return format_int_or_long(obj, format_spec, format_spec_len,
-			 long_format);
+ long_format);
 }
 #endif /* FORMAT_LONG */
 
@@ -995,19 +1024,19 @@
 
 PyObject *
 FORMAT_INT(PyObject *obj,
-	 STRINGLIB_CHAR *format_spec,
-	 Py_ssize_t format_spec_len)
+ STRINGLIB_CHAR *format_spec,
+ Py_ssize_t format_spec_len)
 {
 return format_int_or_long(obj, format_spec, format_spec_len,
-			 int_format);
+ int_format);
 }
 #endif /* FORMAT_INT */
 
 #ifdef FORMAT_FLOAT
 PyObject *
 FORMAT_FLOAT(PyObject *obj,
-	 STRINGLIB_CHAR *format_spec,
-	 Py_ssize_t format_spec_len)
+ STRINGLIB_CHAR *format_spec,
+ Py_ssize_t format_spec_len)
 {
 PyObject *result = NULL;
 InternalFormatSpec format;
@@ -1021,17 +1050,17 @@
 
 /* parse the format_spec */
 if (!parse_internal_render_format_spec(format_spec,
-					 format_spec_len,
-					 &format, '0円'))
+ format_spec_len,
+ &format, '0円'))
 goto done;
 
 /* type conversion? */
 switch (format.type) {
 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 */
+ /* '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':
Modified: python/branches/py3k-short-float-repr/Objects/stringlib/localeutil.h
==============================================================================
--- python/branches/py3k-short-float-repr/Objects/stringlib/localeutil.h	(original)
+++ python/branches/py3k-short-float-repr/Objects/stringlib/localeutil.h	Sun Apr 5 01:04:14 2009
@@ -18,11 +18,13 @@
 * @append_zero_char: If non-zero, put a trailing zero at the end of
 * of the resulting string, if and only if we modified the
 * string.
+ * @grouping: see definition in localeconv().
+ * @thousands_sep: see definition in localeconv().
 *
- * Inserts thousand grouping characters (as defined in the current
- * locale) into the string between buffer and buffer+n_digits. If
- * count is non-NULL, don't do any formatting, just count the number
- * of characters to insert. This is used by the caller to
+ * Inserts thousand grouping characters (as defined by grouping and
+ * thousands_sep) into the string between buffer and buffer+n_digits.
+ * If count is non-NULL, don't do any formatting, just count the
+ * number of characters to insert. This is used by the caller to
 * appropriately resize the buffer, if needed. If count is non-NULL,
 * buffer can be NULL (it is not dereferenced at all in that case).
 *
@@ -34,97 +36,130 @@
 **/
 int
 _Py_InsertThousandsGrouping(STRINGLIB_CHAR *buffer,
-			 Py_ssize_t n_buffer,
-			 Py_ssize_t n_digits,
-			 Py_ssize_t buf_size,
-			 Py_ssize_t *count,
-			 int append_zero_char)
+ Py_ssize_t n_buffer,
+ Py_ssize_t n_digits,
+ Py_ssize_t buf_size,
+ Py_ssize_t *count,
+ int append_zero_char,
+ const char *grouping,
+ const char *thousands_sep)
 {
-	struct lconv *locale_data = localeconv();
-	const char *grouping = locale_data->grouping;
-	const char *thousands_sep = locale_data->thousands_sep;
-	Py_ssize_t thousands_sep_len = strlen(thousands_sep);
-	STRINGLIB_CHAR *pend = NULL; /* current end of buffer */
-	STRINGLIB_CHAR *pmax = NULL; /* max of buffer */
-	char current_grouping;
-	Py_ssize_t remaining = n_digits; /* Number of chars remaining to
-					 be looked at */
-
-	/* Initialize the character count, if we're just counting. */
-	if (count)
-		*count = 0;
-	else {
-		/* We're not just counting, we're modifying buffer */
-		pend = buffer + n_buffer;
-		pmax = buffer + buf_size;
-	}
-
-	/* Starting at the end and working right-to-left, keep track of
-	 what grouping needs to be added and insert that. */
-	current_grouping = *grouping++;
-
-	/* If the first character is 0, perform no grouping at all. */
-	if (current_grouping == 0)
-		return 1;
-
-	while (remaining > current_grouping) {
-		/* Always leave buffer and pend valid at the end of this
-		 loop, since we might leave with a return statement. */
-
-		remaining -= current_grouping;
-		if (count) {
-			/* We're only counting, not touching the memory. */
-			*count += thousands_sep_len;
-		}
-		else {
-			/* Do the formatting. */
-
-			STRINGLIB_CHAR *plast = buffer + remaining;
-
-			/* Is there room to insert thousands_sep_len chars? */
-			if (pmax - pend < thousands_sep_len)
-				/* No room. */
-				return 0;
-
-			/* Move the rest of the string down. */
-			memmove(plast + thousands_sep_len,
-				plast,
-				(pend - plast) * sizeof(STRINGLIB_CHAR));
-			/* Copy the thousands_sep chars into the buffer. */
+ Py_ssize_t thousands_sep_len = strlen(thousands_sep);
+ STRINGLIB_CHAR *pend = NULL; /* current end of buffer */
+ STRINGLIB_CHAR *pmax = NULL; /* max of buffer */
+ char current_grouping;
+ Py_ssize_t remaining = n_digits; /* Number of chars remaining to
+ be looked at */
+
+ /* Initialize the character count, if we're just counting. */
+ if (count)
+ *count = 0;
+ else {
+ /* We're not just counting, we're modifying buffer */
+ pend = buffer + n_buffer;
+ pmax = buffer + buf_size;
+ }
+
+ /* Starting at the end and working right-to-left, keep track of
+ what grouping needs to be added and insert that. */
+ current_grouping = *grouping++;
+
+ /* If the first character is 0, perform no grouping at all. */
+ if (current_grouping == 0)
+ return 1;
+
+ while (remaining > current_grouping) {
+ /* Always leave buffer and pend valid at the end of this
+ loop, since we might leave with a return statement. */
+
+ remaining -= current_grouping;
+ if (count) {
+ /* We're only counting, not touching the memory. */
+ *count += thousands_sep_len;
+ }
+ else {
+ /* Do the formatting. */
+
+ STRINGLIB_CHAR *plast = buffer + remaining;
+
+ /* Is there room to insert thousands_sep_len chars? */
+ if (pmax - pend < thousands_sep_len)
+ /* No room. */
+ return 0;
+
+ /* Move the rest of the string down. */
+ memmove(plast + thousands_sep_len,
+ plast,
+ (pend - plast) * sizeof(STRINGLIB_CHAR));
+ /* Copy the thousands_sep chars into the buffer. */
 #if STRINGLIB_IS_UNICODE
-			/* Convert from the char's of the thousands_sep from
-			 the locale into unicode. */
-			{
-				Py_ssize_t i;
-				for (i = 0; i < thousands_sep_len; ++i)
-					plast[i] = thousands_sep[i];
-			}
+ /* Convert from the char's of the thousands_sep from
+ the locale into unicode. */
+ {
+ Py_ssize_t i;
+ for (i = 0; i < thousands_sep_len; ++i)
+ plast[i] = thousands_sep[i];
+ }
 #else
-			/* No conversion, just memcpy the thousands_sep. */
-			memcpy(plast, thousands_sep, thousands_sep_len);
+ /* No conversion, just memcpy the thousands_sep. */
+ memcpy(plast, thousands_sep, thousands_sep_len);
 #endif
-		}
+ }
 
-		/* Adjust end pointer. */
-		pend += thousands_sep_len;
+ /* Adjust end pointer. */
+ pend += thousands_sep_len;
 
-		/* Move to the next grouping character, unless we're
-		 repeating (which is designated by a grouping of 0). */
-		if (*grouping != 0) {
-			current_grouping = *grouping++;
-			if (current_grouping == CHAR_MAX)
-				/* We're done. */
-				break;
-		}
-	}
-	if (append_zero_char) {
-		/* Append a zero character to mark the end of the string,
-		 if there's room. */
-		if (pend - (buffer + remaining) < 1)
-			/* No room, error. */
-			return 0;
-		*pend = 0;
-	}
-	return 1;
+ /* Move to the next grouping character, unless we're
+ repeating (which is designated by a grouping of 0). */
+ if (*grouping != 0) {
+ current_grouping = *grouping++;
+ if (current_grouping == CHAR_MAX)
+ /* We're done. */
+ break;
+ }
+ }
+ if (append_zero_char) {
+ /* Append a zero character to mark the end of the string,
+ if there's room. */
+ if (pend - (buffer + remaining) < 1)
+ /* No room, error. */
+ return 0;
+ *pend = 0;
+ }
+ return 1;
+}
+
+/**
+ * _Py_InsertThousandsGroupingLocale:
+ * @buffer: A pointer to the start of a string.
+ * @n_buffer: The length of the string.
+ * @n_digits: The number of digits in the string, in which we want
+ * to put the grouping chars.
+ * @buf_size: The maximum size of the buffer pointed to by buffer.
+ * @count: If non-NULL, points to a variable that will receive the
+ * number of characters we need to insert (and no formatting
+ * will actually occur).
+ * @append_zero_char: If non-zero, put a trailing zero at the end of
+ * of the resulting string, if and only if we modified the
+ * string.
+ *
+ * Reads thee current locale and calls _Py_InsertThousandsGrouping().
+ **/
+int
+_Py_InsertThousandsGroupingLocale(STRINGLIB_CHAR *buffer,
+ Py_ssize_t n_buffer,
+ Py_ssize_t n_digits,
+ Py_ssize_t buf_size,
+ Py_ssize_t *count,
+ int append_zero_char)
+{
+ struct lconv *locale_data = localeconv();
+ const char *grouping = locale_data->grouping;
+ const char *thousands_sep = locale_data->thousands_sep;
+
+ return _Py_InsertThousandsGrouping(buffer, n_buffer, n_digits,
+ buf_size, count,
+ append_zero_char, grouping,
+ thousands_sep);
 }
 #endif /* STRINGLIB_LOCALEUTIL_H */
Modified: python/branches/py3k-short-float-repr/Objects/stringlib/stringdefs.h
==============================================================================
--- python/branches/py3k-short-float-repr/Objects/stringlib/stringdefs.h	(original)
+++ python/branches/py3k-short-float-repr/Objects/stringlib/stringdefs.h	Sun Apr 5 01:04:14 2009
@@ -24,5 +24,6 @@
 #define STRINGLIB_CMP memcmp
 #define STRINGLIB_TOSTR PyObject_Str
 #define STRINGLIB_GROUPING _PyBytes_InsertThousandsGrouping
+#define STRINGLIB_GROUPING_LOCALE _PyBytes_InsertThousandsGroupingLocale
 #define STRINGLIB_TOASCII PyObject_Repr
 #endif /* !STRINGLIB_STRINGDEFS_H */
Modified: python/branches/py3k-short-float-repr/Objects/stringlib/unicodedefs.h
==============================================================================
--- python/branches/py3k-short-float-repr/Objects/stringlib/unicodedefs.h	(original)
+++ python/branches/py3k-short-float-repr/Objects/stringlib/unicodedefs.h	Sun Apr 5 01:04:14 2009
@@ -22,6 +22,7 @@
 #define STRINGLIB_RESIZE PyUnicode_Resize
 #define STRINGLIB_CHECK PyUnicode_Check
 #define STRINGLIB_GROUPING _PyUnicode_InsertThousandsGrouping
+#define STRINGLIB_GROUPING_LOCALE _PyUnicode_InsertThousandsGroupingLocale
 
 #if PY_VERSION_HEX < 0x03000000
 #define STRINGLIB_TOSTR PyObject_Unicode
Modified: python/branches/py3k-short-float-repr/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k-short-float-repr/Objects/unicodeobject.c	(original)
+++ python/branches/py3k-short-float-repr/Objects/unicodeobject.c	Sun Apr 5 01:04:14 2009
@@ -5635,6 +5635,7 @@
 #include "stringlib/partition.h"
 
 #define _Py_InsertThousandsGrouping _PyUnicode_InsertThousandsGrouping
+#define _Py_InsertThousandsGroupingLocale _PyUnicode_InsertThousandsGroupingLocale
 #include "stringlib/localeutil.h"
 
 /* helper macro to fixup start/end slice values */
Modified: python/branches/py3k-short-float-repr/PC/VC6/pythoncore.dsp
==============================================================================
--- python/branches/py3k-short-float-repr/PC/VC6/pythoncore.dsp	(original)
+++ python/branches/py3k-short-float-repr/PC/VC6/pythoncore.dsp	Sun Apr 5 01:04:14 2009
@@ -97,14 +97,6 @@
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Modules\_bufferedio.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Modules\_bytesio.c
-# End Source File
-# Begin Source File
-
 SOURCE=..\..\Modules\cjkcodecs\_codecs_cn.c
 # End Source File
 # Begin Source File
@@ -141,19 +133,39 @@
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Modules\_fileio.c
+SOURCE=..\..\Modules\_functoolsmodule.c
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Modules\_functoolsmodule.c
+SOURCE=..\..\Modules\_heapqmodule.c
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Modules\_heapqmodule.c
+SOURCE=..\..\Modules\_io\bytesio.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Modules\_io\stringio.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Modules\_io\fileio.c
+# End Source File
+# Begin Source File
+
+SOURCE="..\..\Modules\_io\bufferedio.c"
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Modules\_io\iobase.c
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Modules\_iobase.c
+SOURCE=..\..\Modules\_io\textio.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Modules\_io\_iomodule.c
 # End Source File
 # Begin Source File
 
@@ -181,10 +193,6 @@
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Modules\_stringio.c
-# End Source File
-# Begin Source File
-
 SOURCE=..\..\Modules\_struct.c
 # End Source File
 # Begin Source File
@@ -193,10 +201,6 @@
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Modules\_textio.c
-# End Source File
-# Begin Source File
-
 SOURCE=..\..\Modules\_threadmodule.c
 # End Source File
 # Begin Source File
@@ -475,10 +479,6 @@
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Modules\io.c
-# End Source File
-# Begin Source File
-
 SOURCE=..\..\Objects\iterobject.c
 # End Source File
 # Begin Source File
Modified: python/branches/py3k-short-float-repr/PC/VS7.1/pythoncore.vcproj
==============================================================================
--- python/branches/py3k-short-float-repr/PC/VS7.1/pythoncore.vcproj	(original)
+++ python/branches/py3k-short-float-repr/PC/VS7.1/pythoncore.vcproj	Sun Apr 5 01:04:14 2009
@@ -274,6 +274,32 @@
 	</References>
 	<Files>
 		<Filter
+			Name="_io"
+ Filter="">
+			<File
+				RelativePath="..\..\Modules\_io\fileio.c">
+			</File>
+			<File
+				RelativePath="..\..\Modules\_io\bytesio.c">
+			</File>
+			<File
+				RelativePath="..\..\Modules\_io\stringio.c">
+			</File>
+			<File
+			 RelativePath="..\..\Modules\_io\bufferedio.c">
+			</File>
+			<File
+				RelativePath="..\..\Modules\_io\iobase.c">
+			</File>
+			<File
+				RelativePath="..\..\Modules\_io\textio.c">
+			</File>
+			<File
+				RelativePath="..\..\Modules\_io\_iomodule.c">
+			</File>
+		</Filter>
+
+		<Filter
 			Name="zlib"
 			Filter="">
 			<File
@@ -362,18 +388,12 @@
 			RelativePath="..\..\Modules\cjkcodecs\_codecs_tw.c">
 		</File>
 		<File
-			RelativePath="..\..\Modules\_bytesio.c">
-		</File>
-		<File
 			RelativePath="..\..\Modules\_codecsmodule.c">
 		</File>
 		<File
 			RelativePath="..\..\Modules\_csv.c">
 		</File>
 		<File
-			RelativePath="..\..\Modules\_fileio.c">
-		</File>
-		<File
 			RelativePath="..\..\Modules\_functoolsmodule.c">
 		</File>
 		<File
@@ -398,9 +418,6 @@
 			RelativePath="..\..\Modules\_sre.c">
 		</File>
 		<File
-			RelativePath="..\..\Modules\_stringio.c">
-		</File>
-		<File
 			RelativePath="..\..\Modules\_struct.c">
 		</File>
 		<File
Modified: python/branches/py3k-short-float-repr/PC/VS8.0/pythoncore.vcproj
==============================================================================
--- python/branches/py3k-short-float-repr/PC/VS8.0/pythoncore.vcproj	(original)
+++ python/branches/py3k-short-float-repr/PC/VS8.0/pythoncore.vcproj	Sun Apr 5 01:04:14 2009
@@ -986,30 +986,38 @@
 				RelativePath="..\..\Modules\_csv.c"
 				>
 			</File>
-			<File
-				RelativePath="..\..\Modules\_fileio.c"
+			<Filter
+				Name="_io"
 				>
-			</File>
- <File
- RelativePath="..\..\Modules\_bytesio.c"
- >
- </File>
- <File
- RelativePath="..\..\Modules\_bufferedio.c"
- >
- </File>
- <File
- RelativePath="..\..\Modules\_iobase.c"
- >
- </File>
- <File
- RelativePath="..\..\Modules\_textio.c"
- >
- </File>
- <File
- RelativePath="..\..\Modules\io.c"
- >
- </File> 
+				<File
+					RelativePath="..\..\Modules\_io\fileio.c"
+					>
+				</File>
+				<File
+					RelativePath="..\..\Modules\_io\bytesio.c"
+					>
+				</File>
+				<File
+					RelativePath="..\..\Modules\_io\stringio.c"
+					>
+				</File>
+				<File
+					RelativePath="..\..\Modules\_io\bufferedio.c"
+					>
+				</File>
+				<File
+					RelativePath="..\..\Modules\_io\iobase.c"
+					>
+				</File>
+				<File
+					RelativePath="..\..\Modules\_io\textio.c"
+					>
+				</File>
+				<File
+					RelativePath="..\..\Modules\_io\_iomodule.c"
+					>
+				</File>
+			</Filter>
 			<File
 				RelativePath="..\..\Modules\_functoolsmodule.c"
 				>
@@ -1043,10 +1051,6 @@
 				>
 			</File>
 			<File
-				RelativePath="..\..\Modules\_stringio.c"
-				>
-			</File>
-			<File
 				RelativePath="..\..\Modules\_struct.c"
 				>
 			</File>
Modified: python/branches/py3k-short-float-repr/PCbuild/pythoncore.vcproj
==============================================================================
--- python/branches/py3k-short-float-repr/PCbuild/pythoncore.vcproj	(original)
+++ python/branches/py3k-short-float-repr/PCbuild/pythoncore.vcproj	Sun Apr 5 01:04:14 2009
@@ -979,10 +979,6 @@
 				>
 			</File>
 			<File
-				RelativePath="..\Modules\_bufferedio.c"
-				>
-			</File>
-			<File
 				RelativePath="..\Modules\_codecsmodule.c"
 				>
 			</File>
@@ -995,14 +991,6 @@
 				>
 			</File>
 			<File
-				RelativePath="..\Modules\_fileio.c"
-				>
-			</File>
- <File
- RelativePath="..\Modules\_bytesio.c"
- >
- </File>
-			<File
 				RelativePath="..\Modules\_functoolsmodule.c"
 				>
 			</File>
@@ -1011,14 +999,6 @@
 				>
 			</File>
 			<File
-				RelativePath="..\Modules\_iobase.c"
-				>
-			</File>
-			<File
-				RelativePath="..\Modules\_iomodule.h"
-				>
-			</File>
-			<File
 				RelativePath="..\Modules\_json.c"
 				>
 			</File>
@@ -1043,18 +1023,10 @@
 				>
 			</File>
 			<File
-				RelativePath="..\Modules\_stringio.c"
-				>
-			</File>
-			<File
 				RelativePath="..\Modules\_struct.c"
 				>
 			</File>
 			<File
-				RelativePath="..\Modules\_textio.c"
-				>
-			</File>
-			<File
 				RelativePath="..\Modules\_weakref.c"
 				>
 			</File>
@@ -1095,10 +1067,6 @@
 				>
 			</File>
 			<File
-				RelativePath="..\Modules\io.c"
-				>
-			</File>
-			<File
 				RelativePath="..\Modules\main.c"
 				>
 			</File>
@@ -1175,6 +1143,42 @@
 				>
 			</File>
 			<Filter
+				Name="_io"
+				>
+				<File
+					RelativePath="..\Modules\_io\fileio.c"
+					>
+				</File>
+				<File
+					RelativePath="..\Modules\_io\bytesio.c"
+					>
+				</File>
+				<File
+					RelativePath="..\Modules\_io\stringio.c"
+					>
+				</File>
+				<File
+					RelativePath="..\Modules\_io\bufferedio.c"
+					>
+				</File>
+				<File
+					RelativePath="..\Modules\_io\iobase.c"
+					>
+				</File>
+				<File
+					RelativePath="..\Modules\_io\textio.c"
+					>
+				</File>
+				<File
+					RelativePath="..\Modules\_io\_iomodule.c"
+					>
+				</File>
+				<File
+					RelativePath="..\Modules\_io\_iomodule.h"
+					>
+				</File>
+			</Filter>
+			<Filter
 				Name="zlib"
 				>
 				<File
Modified: python/branches/py3k-short-float-repr/Parser/parser.c
==============================================================================
--- python/branches/py3k-short-float-repr/Parser/parser.c	(original)
+++ python/branches/py3k-short-float-repr/Parser/parser.c	Sun Apr 5 01:04:14 2009
@@ -149,6 +149,7 @@
 			 strcmp(l->lb_str, s) != 0)
 				continue;
 #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
+#if 0
 /* Leaving this in as an example */
 			if (!(ps->p_flags & CO_FUTURE_WITH_STATEMENT)) {
 				if (s[0] == 'w' && strcmp(s, "with") == 0)
@@ -157,6 +158,7 @@
 					break; /* not a keyword yet */
 			}
 #endif
+#endif
 			D(printf("It's a keyword\n"));
 			return n - i;
 		}
@@ -178,6 +180,7 @@
 }
 
 #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
+#if 0
 /* Leaving this in as an example */
 static void
 future_hack(parser_state *ps)
@@ -218,6 +221,7 @@
 		}
 	}
 }
+#endif
 #endif /* future keyword */
 
 int
@@ -278,11 +282,13 @@
 						 d->d_name,
 						 ps->p_stack.s_top->s_state));
 #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
+#if 0
 					if (d->d_name[0] == 'i' &&
 					 strcmp(d->d_name,
 						 "import_stmt") == 0)
 						future_hack(ps);
 #endif
+#endif
 					s_pop(&ps->p_stack);
 					if (s_empty(&ps->p_stack)) {
 						D(printf(" ACCEPT.\n"));
@@ -296,10 +302,12 @@
 		
 		if (s->s_accept) {
 #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
+#if 0
 			if (d->d_name[0] == 'i' &&
 			 strcmp(d->d_name, "import_stmt") == 0)
 				future_hack(ps);
 #endif
+#endif
 			/* Pop this dfa and try again */
 			s_pop(&ps->p_stack);
 			D(printf(" Pop ...\n"));
Modified: python/branches/py3k-short-float-repr/Parser/parsetok.c
==============================================================================
--- python/branches/py3k-short-float-repr/Parser/parsetok.c	(original)
+++ python/branches/py3k-short-float-repr/Parser/parsetok.c	Sun Apr 5 01:04:14 2009
@@ -100,6 +100,7 @@
 }
 
 #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
+#if 0
 static char with_msg[] =
 "%s:%d: Warning: 'with' will become a reserved keyword in Python 2.6\n";
 
@@ -114,6 +115,7 @@
 	PySys_WriteStderr(msg, filename, lineno);
 }
 #endif
+#endif
 
 /* Parse input coming from the given tokenizer structure.
 Return error code. */
@@ -133,8 +135,8 @@
 		return NULL;
 	}
 #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
-	if (*flags & PyPARSE_WITH_IS_KEYWORD)
-		ps->p_flags |= CO_FUTURE_WITH_STATEMENT;
+	if (*flags & PyPARSE_BARRY_AS_BDFL)
+		ps->p_flags |= CO_FUTURE_BARRY_AS_BDFL;
 #endif
 
 	for (;;) {
@@ -177,26 +179,20 @@
 		str[len] = '0円';
 
 #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
-		/* This is only necessary to support the "as" warning, but
-		 we don't want to warn about "as" in import statements. */
-		if (type == NAME &&
-		 len == 6 && str[0] == 'i' && strcmp(str, "import") == 0)
-			handling_import = 1;
-
-		/* Warn about with as NAME */
-		if (type == NAME &&
-		 !(ps->p_flags & CO_FUTURE_WITH_STATEMENT)) {
-		 if (len == 4 && str[0] == 'w' && strcmp(str, "with") == 0)
-			warn(with_msg, err_ret->filename, tok->lineno);
-		 else if (!(handling_import || handling_with) &&
-		 len == 2 && str[0] == 'a' &&
-			 strcmp(str, "as") == 0)
-			warn(as_msg, err_ret->filename, tok->lineno);
-		}
-		else if (type == NAME &&
-			 (ps->p_flags & CO_FUTURE_WITH_STATEMENT) &&
-			 len == 4 && str[0] == 'w' && strcmp(str, "with") == 0)
-			handling_with = 1;
+		if (type == NOTEQUAL) {
+			if (!(ps->p_flags & CO_FUTURE_BARRY_AS_BDFL) &&
+					strcmp(str, "!=")) {
+				err_ret->error = E_SYNTAX;
+				break;
+			}
+			else if ((ps->p_flags & CO_FUTURE_BARRY_AS_BDFL) &&
+					strcmp(str, "<>")) {
+				err_ret->text = "with Barry as BDFL, use '<>' "
+						"instead of '!='";
+				err_ret->error = E_SYNTAX;
+				break;
+			}
+		}
 #endif
 		if (a >= tok->line_start)
 			col_offset = a - tok->line_start;
Modified: python/branches/py3k-short-float-repr/Parser/tokenizer.c
==============================================================================
--- python/branches/py3k-short-float-repr/Parser/tokenizer.c	(original)
+++ python/branches/py3k-short-float-repr/Parser/tokenizer.c	Sun Apr 5 01:04:14 2009
@@ -1040,6 +1040,7 @@
 		break;
 	case '<':
 		switch (c2) {
+		case '>':	return NOTEQUAL;
 		case '=':	return LESSEQUAL;
 		case '<':	return LEFTSHIFT;
 		}
Modified: python/branches/py3k-short-float-repr/Python/_warnings.c
==============================================================================
--- python/branches/py3k-short-float-repr/Python/_warnings.c	(original)
+++ python/branches/py3k-short-float-repr/Python/_warnings.c	Sun Apr 5 01:04:14 2009
@@ -2,7 +2,6 @@
 #include "frameobject.h"
 
 #define MODULE_NAME "_warnings"
-#define DEFAULT_ACTION_NAME "default_action"
 
 PyDoc_STRVAR(warnings__doc__,
 MODULE_NAME " provides basic warning filtering support.\n"
@@ -12,6 +11,7 @@
 get_warnings_attr() will reset these variables accordingly. */
 static PyObject *_filters; /* List */
 static PyObject *_once_registry; /* Dict */
+static PyObject *_default_action; /* String */
 
 
 static int
@@ -78,12 +78,31 @@
 }
 
 
+static PyObject *
+get_default_action(void)
+{
+ PyObject *default_action;
+
+ default_action = get_warnings_attr("defaultaction");
+ if (default_action == NULL) {
+	if (PyErr_Occurred()) {
+	 return NULL;
+	}
+	return _default_action;
+ }
+
+ Py_DECREF(_default_action);
+ _default_action = default_action;
+ return default_action;
+}
+
+
 /* The item is a borrowed reference. */
 static const char *
 get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno,
 PyObject *module, PyObject **item)
 {
- PyObject *action, *m, *d;
+ PyObject *action;
 Py_ssize_t i;
 PyObject *warnings_filters;
 
@@ -135,22 +154,17 @@
 return _PyUnicode_AsString(action);
 }
 
- m = PyImport_ImportModule(MODULE_NAME);
- if (m == NULL)
- return NULL;
- d = PyModule_GetDict(m);
- Py_DECREF(m);
- if (d == NULL)
- return NULL;
- action = PyDict_GetItemString(d, DEFAULT_ACTION_NAME);
- if (action != NULL)
+ action = get_default_action();
+ if (action != NULL) {
 return _PyUnicode_AsString(action);
+ }
 
 PyErr_SetString(PyExc_ValueError,
- MODULE_NAME "." DEFAULT_ACTION_NAME " not found");
+ MODULE_NAME ".defaultaction not found");
 return NULL;
 }
 
+
 static int
 already_warned(PyObject *registry, PyObject *key, int should_set)
 {
@@ -874,7 +888,7 @@
 PyMODINIT_FUNC
 _PyWarnings_Init(void)
 {
- PyObject *m, *default_action;
+ PyObject *m;
 
 m = PyModule_Create(&warningsmodule);
 if (m == NULL)
@@ -894,10 +908,10 @@
 if (PyModule_AddObject(m, "once_registry", _once_registry) < 0)
 return NULL;
 
- default_action = PyUnicode_InternFromString("default");
- if (default_action == NULL)
+ _default_action = PyUnicode_FromString("default");
+ if (_default_action == NULL)
 return NULL;
- if (PyModule_AddObject(m, DEFAULT_ACTION_NAME, default_action) < 0)
+ if (PyModule_AddObject(m, "default_action", _default_action) < 0)
 return NULL;
 return m;
 }
Modified: python/branches/py3k-short-float-repr/Python/future.c
==============================================================================
--- python/branches/py3k-short-float-repr/Python/future.c	(original)
+++ python/branches/py3k-short-float-repr/Python/future.c	Sun Apr 5 01:04:14 2009
@@ -39,6 +39,8 @@
 			continue;
 		} else if (strcmp(feature, FUTURE_UNICODE_LITERALS) == 0) {
 			continue;
+		} else if (strcmp(feature, FUTURE_BARRY_AS_BDFL) == 0) {
+			ff->ff_features |= CO_FUTURE_BARRY_AS_BDFL;
 		} else if (strcmp(feature, "braces") == 0) {
 			PyErr_SetString(PyExc_SyntaxError,
 					"not a chance");
Modified: python/branches/py3k-short-float-repr/Python/getargs.c
==============================================================================
--- python/branches/py3k-short-float-repr/Python/getargs.c	(original)
+++ python/branches/py3k-short-float-repr/Python/getargs.c	Sun Apr 5 01:04:14 2009
@@ -776,24 +776,18 @@
 		char *p = va_arg(*p_va, char *);
 		if (PyBytes_Check(arg) && PyBytes_Size(arg) == 1)
 			*p = PyBytes_AS_STRING(arg)[0];
-		else if (PyUnicode_Check(arg) &&
-			 PyUnicode_GET_SIZE(arg) == 1 &&
-			 PyUnicode_AS_UNICODE(arg)[0] < 256)
-			*p = (char)PyUnicode_AS_UNICODE(arg)[0];
 		else
-			return converterr("char < 256", arg, msgbuf, bufsize);
+			return converterr("a byte string of length 1", arg, msgbuf, bufsize);
 		break;
 	}
 
 	case 'C': {/* unicode char */
 		int *p = va_arg(*p_va, int *);
-		if (PyBytes_Check(arg) && PyBytes_Size(arg) == 1)
-			*p = PyBytes_AS_STRING(arg)[0];
-		else if (PyUnicode_Check(arg) &&
-			 PyUnicode_GET_SIZE(arg) == 1)
+		if (PyUnicode_Check(arg) &&
+ PyUnicode_GET_SIZE(arg) == 1)
 			*p = PyUnicode_AS_UNICODE(arg)[0];
 		else
-			return converterr("char", arg, msgbuf, bufsize);
+			return converterr("a unicode character", arg, msgbuf, bufsize);
 		break;
 	}
 
Modified: python/branches/py3k-short-float-repr/Python/graminit.c
==============================================================================
--- python/branches/py3k-short-float-repr/Python/graminit.c	(original)
+++ python/branches/py3k-short-float-repr/Python/graminit.c	Sun Apr 5 01:04:14 2009
@@ -1129,16 +1129,17 @@
 	{1, arcs_52_0},
 	{2, arcs_52_1},
 };
-static arc arcs_53_0[9] = {
+static arc arcs_53_0[10] = {
 	{118, 1},
 	{119, 1},
 	{120, 1},
 	{121, 1},
 	{122, 1},
 	{123, 1},
+	{124, 1},
 	{95, 1},
 	{114, 2},
-	{124, 3},
+	{125, 3},
 };
 static arc arcs_53_1[1] = {
 	{0, 1},
@@ -1151,7 +1152,7 @@
 	{0, 3},
 };
 static state states_53[4] = {
-	{9, arcs_53_0},
+	{10, arcs_53_0},
 	{1, arcs_53_1},
 	{1, arcs_53_2},
 	{2, arcs_53_3},
@@ -1172,10 +1173,10 @@
 	{1, arcs_54_2},
 };
 static arc arcs_55_0[1] = {
-	{125, 1},
+	{126, 1},
 };
 static arc arcs_55_1[2] = {
-	{126, 0},
+	{127, 0},
 	{0, 1},
 };
 static state states_55[2] = {
@@ -1183,10 +1184,10 @@
 	{2, arcs_55_1},
 };
 static arc arcs_56_0[1] = {
-	{127, 1},
+	{128, 1},
 };
 static arc arcs_56_1[2] = {
-	{128, 0},
+	{129, 0},
 	{0, 1},
 };
 static state states_56[2] = {
@@ -1194,10 +1195,10 @@
 	{2, arcs_56_1},
 };
 static arc arcs_57_0[1] = {
-	{129, 1},
+	{130, 1},
 };
 static arc arcs_57_1[2] = {
-	{130, 0},
+	{131, 0},
 	{0, 1},
 };
 static state states_57[2] = {
@@ -1205,11 +1206,11 @@
 	{2, arcs_57_1},
 };
 static arc arcs_58_0[1] = {
-	{131, 1},
+	{132, 1},
 };
 static arc arcs_58_1[3] = {
-	{132, 0},
 	{133, 0},
+	{134, 0},
 	{0, 1},
 };
 static state states_58[2] = {
@@ -1217,11 +1218,11 @@
 	{3, arcs_58_1},
 };
 static arc arcs_59_0[1] = {
-	{134, 1},
+	{135, 1},
 };
 static arc arcs_59_1[3] = {
-	{135, 0},
 	{136, 0},
+	{137, 0},
 	{0, 1},
 };
 static state states_59[2] = {
@@ -1229,13 +1230,13 @@
 	{3, arcs_59_1},
 };
 static arc arcs_60_0[1] = {
-	{137, 1},
+	{138, 1},
 };
 static arc arcs_60_1[5] = {
 	{31, 0},
-	{138, 0},
 	{139, 0},
 	{140, 0},
+	{141, 0},
 	{0, 1},
 };
 static state states_60[2] = {
@@ -1243,13 +1244,13 @@
 	{5, arcs_60_1},
 };
 static arc arcs_61_0[4] = {
-	{135, 1},
 	{136, 1},
-	{141, 1},
-	{142, 2},
+	{137, 1},
+	{142, 1},
+	{143, 2},
 };
 static arc arcs_61_1[1] = {
-	{137, 2},
+	{138, 2},
 };
 static arc arcs_61_2[1] = {
 	{0, 2},
@@ -1260,15 +1261,15 @@
 	{1, arcs_61_2},
 };
 static arc arcs_62_0[1] = {
-	{143, 1},
+	{144, 1},
 };
 static arc arcs_62_1[3] = {
-	{144, 1},
+	{145, 1},
 	{32, 2},
 	{0, 1},
 };
 static arc arcs_62_2[1] = {
-	{137, 3},
+	{138, 3},
 };
 static arc arcs_62_3[1] = {
 	{0, 3},
@@ -1281,44 +1282,44 @@
 };
 static arc arcs_63_0[10] = {
 	{13, 1},
-	{146, 2},
-	{148, 3},
+	{147, 2},
+	{149, 3},
 	{21, 4},
-	{151, 4},
-	{152, 5},
+	{152, 4},
+	{153, 5},
 	{77, 4},
-	{153, 4},
 	{154, 4},
 	{155, 4},
+	{156, 4},
 };
 static arc arcs_63_1[3] = {
 	{46, 6},
-	{145, 6},
+	{146, 6},
 	{15, 4},
 };
 static arc arcs_63_2[2] = {
-	{145, 7},
-	{147, 4},
+	{146, 7},
+	{148, 4},
 };
 static arc arcs_63_3[2] = {
-	{149, 8},
-	{150, 4},
+	{150, 8},
+	{151, 4},
 };
 static arc arcs_63_4[1] = {
 	{0, 4},
 };
 static arc arcs_63_5[2] = {
-	{152, 5},
+	{153, 5},
 	{0, 5},
 };
 static arc arcs_63_6[1] = {
 	{15, 4},
 };
 static arc arcs_63_7[1] = {
-	{147, 4},
+	{148, 4},
 };
 static arc arcs_63_8[1] = {
-	{150, 4},
+	{151, 4},
 };
 static state states_63[9] = {
 	{10, arcs_63_0},
@@ -1335,7 +1336,7 @@
 	{24, 1},
 };
 static arc arcs_64_1[3] = {
-	{156, 2},
+	{157, 2},
 	{30, 3},
 	{0, 1},
 };
@@ -1359,7 +1360,7 @@
 };
 static arc arcs_65_0[3] = {
 	{13, 1},
-	{146, 2},
+	{147, 2},
 	{76, 3},
 };
 static arc arcs_65_1[2] = {
@@ -1367,7 +1368,7 @@
 	{15, 5},
 };
 static arc arcs_65_2[1] = {
-	{157, 6},
+	{158, 6},
 };
 static arc arcs_65_3[1] = {
 	{21, 5},
@@ -1379,7 +1380,7 @@
 	{0, 5},
 };
 static arc arcs_65_6[1] = {
-	{147, 5},
+	{148, 5},
 };
 static state states_65[7] = {
 	{3, arcs_65_0},
@@ -1391,14 +1392,14 @@
 	{1, arcs_65_6},
 };
 static arc arcs_66_0[1] = {
-	{158, 1},
+	{159, 1},
 };
 static arc arcs_66_1[2] = {
 	{30, 2},
 	{0, 1},
 };
 static arc arcs_66_2[2] = {
-	{158, 1},
+	{159, 1},
 	{0, 2},
 };
 static state states_66[3] = {
@@ -1416,11 +1417,11 @@
 };
 static arc arcs_67_2[3] = {
 	{24, 3},
-	{159, 4},
+	{160, 4},
 	{0, 2},
 };
 static arc arcs_67_3[2] = {
-	{159, 4},
+	{160, 4},
 	{0, 3},
 };
 static arc arcs_67_4[1] = {
@@ -1485,7 +1486,7 @@
 };
 static arc arcs_71_1[4] = {
 	{25, 2},
-	{156, 3},
+	{157, 3},
 	{30, 4},
 	{0, 1},
 };
@@ -1500,7 +1501,7 @@
 	{0, 4},
 };
 static arc arcs_71_5[3] = {
-	{156, 3},
+	{157, 3},
 	{30, 7},
 	{0, 5},
 };
@@ -1536,7 +1537,7 @@
 	{2, arcs_71_10},
 };
 static arc arcs_72_0[1] = {
-	{160, 1},
+	{161, 1},
 };
 static arc arcs_72_1[1] = {
 	{21, 2},
@@ -1572,7 +1573,7 @@
 	{1, arcs_72_7},
 };
 static arc arcs_73_0[3] = {
-	{161, 1},
+	{162, 1},
 	{31, 2},
 	{32, 3},
 };
@@ -1587,7 +1588,7 @@
 	{24, 6},
 };
 static arc arcs_73_4[4] = {
-	{161, 1},
+	{162, 1},
 	{31, 2},
 	{32, 3},
 	{0, 4},
@@ -1600,7 +1601,7 @@
 	{0, 6},
 };
 static arc arcs_73_7[2] = {
-	{161, 5},
+	{162, 5},
 	{32, 3},
 };
 static state states_73[8] = {
@@ -1617,7 +1618,7 @@
 	{24, 1},
 };
 static arc arcs_74_1[3] = {
-	{156, 2},
+	{157, 2},
 	{29, 3},
 	{0, 1},
 };
@@ -1634,8 +1635,8 @@
 	{1, arcs_74_3},
 };
 static arc arcs_75_0[2] = {
-	{156, 1},
-	{163, 1},
+	{157, 1},
+	{164, 1},
 };
 static arc arcs_75_1[1] = {
 	{0, 1},
@@ -1657,7 +1658,7 @@
 	{105, 4},
 };
 static arc arcs_76_4[2] = {
-	{162, 5},
+	{163, 5},
 	{0, 4},
 };
 static arc arcs_76_5[1] = {
@@ -1678,7 +1679,7 @@
 	{107, 2},
 };
 static arc arcs_77_2[2] = {
-	{162, 3},
+	{163, 3},
 	{0, 2},
 };
 static arc arcs_77_3[1] = {
@@ -1712,7 +1713,7 @@
 	{1, arcs_79_1},
 };
 static arc arcs_80_0[1] = {
-	{166, 1},
+	{167, 1},
 };
 static arc arcs_80_1[2] = {
 	{9, 2},
@@ -1728,11 +1729,11 @@
 };
 static dfa dfas[81] = {
 	{256, "single_input", 0, 3, states_0,
-	 "004円050円060円200円000円000円000円050円370円044円034円144円011円040円004円000円200円041円224円017円101円"},
+	 "004円050円060円200円000円000円000円050円370円044円034円144円011円040円004円000円000円103円050円037円202円"},
 	{257, "file_input", 0, 2, states_1,
-	 "204円050円060円200円000円000円000円050円370円044円034円144円011円040円004円000円200円041円224円017円101円"},
+	 "204円050円060円200円000円000円000円050円370円044円034円144円011円040円004円000円000円103円050円037円202円"},
 	{258, "eval_input", 0, 3, states_2,
-	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円200円041円224円017円000円"},
+	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円000円103円050円037円000円"},
 	{259, "decorator", 0, 7, states_3,
 	 "000円010円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円"},
 	{260, "decorators", 0, 2, states_4,
@@ -1752,13 +1753,13 @@
 	{267, "vfpdef", 0, 2, states_11,
 	 "000円000円040円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円"},
 	{268, "stmt", 0, 2, states_12,
-	 "000円050円060円200円000円000円000円050円370円044円034円144円011円040円004円000円200円041円224円017円101円"},
+	 "000円050円060円200円000円000円000円050円370円044円034円144円011円040円004円000円000円103円050円037円202円"},
 	{269, "simple_stmt", 0, 4, states_13,
-	 "000円040円040円200円000円000円000円050円370円044円034円000円000円040円004円000円200円041円224円017円100円"},
+	 "000円040円040円200円000円000円000円050円370円044円034円000円000円040円004円000円000円103円050円037円200円"},
 	{270, "small_stmt", 0, 2, states_14,
-	 "000円040円040円200円000円000円000円050円370円044円034円000円000円040円004円000円200円041円224円017円100円"},
+	 "000円040円040円200円000円000円000円050円370円044円034円000円000円040円004円000円000円103円050円037円200円"},
 	{271, "expr_stmt", 0, 6, states_15,
-	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円200円041円224円017円000円"},
+	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円000円103円050円037円000円"},
 	{272, "augassign", 0, 2, states_16,
 	 "000円000円000円000円000円200円377円007円000円000円000円000円000円000円000円000円000円000円000円000円000円"},
 	{273, "del_stmt", 0, 3, states_17,
@@ -1766,7 +1767,7 @@
 	{274, "pass_stmt", 0, 2, states_18,
 	 "000円000円000円000円000円000円000円040円000円000円000円000円000円000円000円000円000円000円000円000円000円"},
 	{275, "flow_stmt", 0, 2, states_19,
-	 "000円000円000円000円000円000円000円000円170円000円000円000円000円000円000円000円000円000円000円000円100円"},
+	 "000円000円000円000円000円000円000円000円170円000円000円000円000円000円000円000円000円000円000円000円200円"},
 	{276, "break_stmt", 0, 2, states_20,
 	 "000円000円000円000円000円000円000円000円010円000円000円000円000円000円000円000円000円000円000円000円000円"},
 	{277, "continue_stmt", 0, 2, states_21,
@@ -1774,7 +1775,7 @@
 	{278, "return_stmt", 0, 3, states_22,
 	 "000円000円000円000円000円000円000円000円040円000円000円000円000円000円000円000円000円000円000円000円000円"},
 	{279, "yield_stmt", 0, 2, states_23,
-	 "000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円100円"},
+	 "000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円200円"},
 	{280, "raise_stmt", 0, 5, states_24,
 	 "000円000円000円000円000円000円000円000円100円000円000円000円000円000円000円000円000円000円000円000円000円"},
 	{281, "import_stmt", 0, 2, states_25,
@@ -1800,7 +1801,7 @@
 	{291, "assert_stmt", 0, 5, states_35,
 	 "000円000円000円000円000円000円000円000円000円000円020円000円000円000円000円000円000円000円000円000円000円"},
 	{292, "compound_stmt", 0, 2, states_36,
-	 "000円010円020円000円000円000円000円000円000円000円000円144円011円000円000円000円000円000円000円000円001円"},
+	 "000円010円020円000円000円000円000円000円000円000円000円144円011円000円000円000円000円000円000円000円002円"},
 	{293, "if_stmt", 0, 8, states_37,
 	 "000円000円000円000円000円000円000円000円000円000円000円004円000円000円000円000円000円000円000円000円000円"},
 	{294, "while_stmt", 0, 8, states_38,
@@ -1816,67 +1817,67 @@
 	{299, "except_clause", 0, 5, states_43,
 	 "000円000円000円000円000円000円000円000円000円000円000円000円100円000円000円000円000円000円000円000円000円"},
 	{300, "suite", 0, 5, states_44,
-	 "004円040円040円200円000円000円000円050円370円044円034円000円000円040円004円000円200円041円224円017円100円"},
+	 "004円040円040円200円000円000円000円050円370円044円034円000円000円040円004円000円000円103円050円037円200円"},
 	{301, "test", 0, 6, states_45,
-	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円200円041円224円017円000円"},
+	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円000円103円050円037円000円"},
 	{302, "test_nocond", 0, 2, states_46,
-	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円200円041円224円017円000円"},
+	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円000円103円050円037円000円"},
 	{303, "lambdef", 0, 5, states_47,
 	 "000円000円000円000円000円000円000円000円000円000円000円000円000円040円000円000円000円000円000円000円000円"},
 	{304, "lambdef_nocond", 0, 5, states_48,
 	 "000円000円000円000円000円000円000円000円000円000円000円000円000円040円000円000円000円000円000円000円000円"},
 	{305, "or_test", 0, 2, states_49,
-	 "000円040円040円200円000円000円000円000円000円040円000円000円000円000円004円000円200円041円224円017円000円"},
+	 "000円040円040円200円000円000円000円000円000円040円000円000円000円000円004円000円000円103円050円037円000円"},
 	{306, "and_test", 0, 2, states_50,
-	 "000円040円040円200円000円000円000円000円000円040円000円000円000円000円004円000円200円041円224円017円000円"},
+	 "000円040円040円200円000円000円000円000円000円040円000円000円000円000円004円000円000円103円050円037円000円"},
 	{307, "not_test", 0, 3, states_51,
-	 "000円040円040円200円000円000円000円000円000円040円000円000円000円000円004円000円200円041円224円017円000円"},
+	 "000円040円040円200円000円000円000円000円000円040円000円000円000円000円004円000円000円103円050円037円000円"},
 	{308, "comparison", 0, 2, states_52,
-	 "000円040円040円200円000円000円000円000円000円040円000円000円000円000円000円000円200円041円224円017円000円"},
+	 "000円040円040円200円000円000円000円000円000円040円000円000円000円000円000円000円000円103円050円037円000円"},
 	{309, "comp_op", 0, 4, states_53,
-	 "000円000円000円000円000円000円000円000円000円000円000円200円000円000円304円037円000円000円000円000円000円"},
+	 "000円000円000円000円000円000円000円000円000円000円000円200円000円000円304円077円000円000円000円000円000円"},
 	{310, "star_expr", 0, 3, states_54,
-	 "000円040円040円200円000円000円000円000円000円040円000円000円000円000円000円000円200円041円224円017円000円"},
+	 "000円040円040円200円000円000円000円000円000円040円000円000円000円000円000円000円000円103円050円037円000円"},
 	{311, "expr", 0, 2, states_55,
-	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円200円041円224円017円000円"},
+	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円000円103円050円037円000円"},
 	{312, "xor_expr", 0, 2, states_56,
-	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円200円041円224円017円000円"},
+	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円000円103円050円037円000円"},
 	{313, "and_expr", 0, 2, states_57,
-	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円200円041円224円017円000円"},
+	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円000円103円050円037円000円"},
 	{314, "shift_expr", 0, 2, states_58,
-	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円200円041円224円017円000円"},
+	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円000円103円050円037円000円"},
 	{315, "arith_expr", 0, 2, states_59,
-	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円200円041円224円017円000円"},
+	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円000円103円050円037円000円"},
 	{316, "term", 0, 2, states_60,
-	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円200円041円224円017円000円"},
+	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円000円103円050円037円000円"},
 	{317, "factor", 0, 3, states_61,
-	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円200円041円224円017円000円"},
+	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円000円103円050円037円000円"},
 	{318, "power", 0, 4, states_62,
-	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円000円000円224円017円000円"},
+	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円000円000円050円037円000円"},
 	{319, "atom", 0, 9, states_63,
-	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円000円000円224円017円000円"},
+	 "000円040円040円000円000円000円000円000円000円040円000円000円000円000円000円000円000円000円050円037円000円"},
 	{320, "testlist_comp", 0, 5, states_64,
-	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円200円041円224円017円000円"},
+	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円000円103円050円037円000円"},
 	{321, "trailer", 0, 7, states_65,
-	 "000円040円000円000円000円000円000円000円000円020円000円000円000円000円000円000円000円000円004円000円000円"},
+	 "000円040円000円000円000円000円000円000円000円020円000円000円000円000円000円000円000円000円010円000円000円"},
 	{322, "subscriptlist", 0, 3, states_66,
-	 "000円040円040円202円000円000円000円000円000円040円000円000円000円040円004円000円200円041円224円017円000円"},
+	 "000円040円040円202円000円000円000円000円000円040円000円000円000円040円004円000円000円103円050円037円000円"},
 	{323, "subscript", 0, 5, states_67,
-	 "000円040円040円202円000円000円000円000円000円040円000円000円000円040円004円000円200円041円224円017円000円"},
+	 "000円040円040円202円000円000円000円000円000円040円000円000円000円040円004円000円000円103円050円037円000円"},
 	{324, "sliceop", 0, 3, states_68,
 	 "000円000円000円002円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円"},
 	{325, "exprlist", 0, 3, states_69,
-	 "000円040円040円200円000円000円000円000円000円040円000円000円000円000円000円000円200円041円224円017円000円"},
+	 "000円040円040円200円000円000円000円000円000円040円000円000円000円000円000円000円000円103円050円037円000円"},
 	{326, "testlist", 0, 3, states_70,
-	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円200円041円224円017円000円"},
+	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円000円103円050円037円000円"},
 	{327, "dictorsetmaker", 0, 11, states_71,
-	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円200円041円224円017円000円"},
+	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円000円103円050円037円000円"},
 	{328, "classdef", 0, 8, states_72,
-	 "000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円001円"},
+	 "000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円002円"},
 	{329, "arglist", 0, 8, states_73,
-	 "000円040円040円200円001円000円000円000円000円040円000円000円000円040円004円000円200円041円224円017円000円"},
+	 "000円040円040円200円001円000円000円000円000円040円000円000円000円040円004円000円000円103円050円037円000円"},
 	{330, "argument", 0, 4, states_74,
-	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円200円041円224円017円000円"},
+	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円000円103円050円037円000円"},
 	{331, "comp_iter", 0, 2, states_75,
 	 "000円000円000円000円000円000円000円000円000円000円000円104円000円000円000円000円000円000円000円000円000円"},
 	{332, "comp_for", 0, 6, states_76,
@@ -1884,13 +1885,13 @@
 	{333, "comp_if", 0, 4, states_77,
 	 "000円000円000円000円000円000円000円000円000円000円000円004円000円000円000円000円000円000円000円000円000円"},
 	{334, "testlist1", 0, 2, states_78,
-	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円200円041円224円017円000円"},
+	 "000円040円040円200円000円000円000円000円000円040円000円000円000円040円004円000円000円103円050円037円000円"},
 	{335, "encoding_decl", 0, 2, states_79,
 	 "000円000円040円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円"},
 	{336, "yield_expr", 0, 3, states_80,
-	 "000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円100円"},
+	 "000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円000円200円"},
 };
-static label labels[167] = {
+static label labels[168] = {
 	{0, "EMPTY"},
 	{256, 0},
 	{4, 0},
@@ -2015,6 +2016,7 @@
 	{31, 0},
 	{30, 0},
 	{29, 0},
+	{29, 0},
 	{1, "is"},
 	{312, 0},
 	{18, 0},
@@ -2062,6 +2064,6 @@
 grammar _PyParser_Grammar = {
 	81,
 	dfas,
-	{167, labels},
+	{168, labels},
 	256
 };
Modified: python/branches/py3k-short-float-repr/Python/import.c
==============================================================================
--- python/branches/py3k-short-float-repr/Python/import.c	(original)
+++ python/branches/py3k-short-float-repr/Python/import.c	Sun Apr 5 01:04:14 2009
@@ -3023,13 +3023,21 @@
 		int fd = PyObject_AsFileDescriptor(fob);
 		if (fd == -1)
 			return NULL;
-		/* XXX This will leak a FILE struct. Fix this!!!!
-		 (But it doesn't leak a file descrioptor!) */
+		if (!_PyVerify_fd(fd))
+			goto error;
+		/* the FILE struct gets a new fd, so that it can be closed
+		 * independently of the file descriptor given
+		 */
+		fd = dup(fd);
+		if (fd == -1)
+			goto error;
 		fp = fdopen(fd, mode);
 	}
-	if (fp == NULL)
-		PyErr_SetFromErrno(PyExc_IOError);
-	return fp;
+	if (fp)
+		return fp;
+error:
+	PyErr_SetFromErrno(PyExc_IOError);
+	return NULL;
 }
 
 static PyObject *
@@ -3040,15 +3048,19 @@
 	PyObject *fob = NULL;
 	PyObject *m;
 	FILE *fp;
-	if (!PyArg_ParseTuple(args, "ss|O:load_compiled",
-			 &name, &pathname, &fob))
+	if (!PyArg_ParseTuple(args, "ses|O:load_compiled",
+			 &name, 
+			 Py_FileSystemDefaultEncoding, &pathname, 
+			 &fob))
 		return NULL;
 	fp = get_file(pathname, fob, "rb");
-	if (fp == NULL)
+	if (fp == NULL) {
+		PyMem_Free(pathname);
 		return NULL;
+	}
 	m = load_compiled_module(name, pathname, fp);
-	if (fob == NULL)
-		fclose(fp);
+	fclose(fp);
+	PyMem_Free(pathname);
 	return m;
 }
 
@@ -3062,15 +3074,22 @@
 	PyObject *fob = NULL;
 	PyObject *m;
 	FILE *fp = NULL;
-	if (!PyArg_ParseTuple(args, "ss|O:load_dynamic",
-			 &name, &pathname, &fob))
+	if (!PyArg_ParseTuple(args, "ses|O:load_dynamic",
+			 &name, 
+			 Py_FileSystemDefaultEncoding, &pathname, 
+			 &fob))
 		return NULL;
 	if (fob) {
 		fp = get_file(pathname, fob, "r");
-		if (fp == NULL)
+		if (fp == NULL) {
+			PyMem_Free(pathname);
 			return NULL;
+		}
 	}
 	m = _PyImport_LoadDynamicModule(name, pathname, fp);
+	PyMem_Free(pathname);
+	if (fp)
+		fclose(fp);
 	return m;
 }
 
@@ -3084,15 +3103,19 @@
 	PyObject *fob = NULL;
 	PyObject *m;
 	FILE *fp;
-	if (!PyArg_ParseTuple(args, "ss|O:load_source",
-			 &name, &pathname, &fob))
+	if (!PyArg_ParseTuple(args, "ses|O:load_source",
+			 &name, 
+			 Py_FileSystemDefaultEncoding, &pathname,
+			 &fob))
 		return NULL;
 	fp = get_file(pathname, fob, "r");
-	if (fp == NULL)
+	if (fp == NULL) {
+		PyMem_Free(pathname);
 		return NULL;
+	}
 	m = load_source_module(name, pathname, fp);
-	if (fob == NULL)
-		fclose(fp);
+	PyMem_Free(pathname);
+	fclose(fp);
 	return m;
 }
 
@@ -3102,13 +3125,15 @@
 	char *name;
 	PyObject *fob;
 	char *pathname;
+	PyObject * ret;
 	char *suffix; /* Unused */
 	char *mode;
 	int type;
 	FILE *fp;
 
-	if (!PyArg_ParseTuple(args, "sOs(ssi):load_module",
-			 &name, &fob, &pathname,
+	if (!PyArg_ParseTuple(args, "sOes(ssi):load_module",
+			 &name, &fob, 
+			 Py_FileSystemDefaultEncoding, &pathname,
 			 &suffix, &mode, &type))
 		return NULL;
 	if (*mode) {
@@ -3119,6 +3144,7 @@
 		if (!(*mode == 'r' || *mode == 'U') || strchr(mode, '+')) {
 			PyErr_Format(PyExc_ValueError,
 				 "invalid file open mode %.200s", mode);
+			PyMem_Free(pathname);
 			return NULL;
 		}
 	}
@@ -3126,10 +3152,16 @@
 		fp = NULL;
 	else {
 		fp = get_file(NULL, fob, mode);
-		if (fp == NULL)
+		if (fp == NULL) {
+			PyMem_Free(pathname);
 			return NULL;
-	}
-	return load_module(name, fp, pathname, type, NULL);
+		}
+	} 
+	ret = load_module(name, fp, pathname, type, NULL);
+	PyMem_Free(pathname);
+	if (fp)
+		fclose(fp);
+	return ret;
 }
 
 static PyObject *
@@ -3137,9 +3169,13 @@
 {
 	char *name;
 	char *pathname;
-	if (!PyArg_ParseTuple(args, "ss:load_package", &name, &pathname))
+	PyObject * ret;
+	if (!PyArg_ParseTuple(args, "ses:load_package", 
+			 &name, Py_FileSystemDefaultEncoding, &pathname))
 		return NULL;
-	return load_package(name, pathname);
+	ret = load_package(name, pathname);
+	PyMem_Free(pathname);
+	return ret;
 }
 
 static PyObject *
@@ -3452,13 +3488,13 @@
 /* Shorthand to add a single entry given a name and a function */
 
 int
-PyImport_AppendInittab(char *name, PyObject* (*initfunc)(void))
+PyImport_AppendInittab(const char *name, PyObject* (*initfunc)(void))
 {
 	struct _inittab newtab[2];
 
 	memset(newtab, '0円', sizeof newtab);
 
-	newtab[0].name = name;
+	newtab[0].name = (char *)name;
 	newtab[0].initfunc = initfunc;
 
 	return PyImport_ExtendInittab(newtab);
Modified: python/branches/py3k-short-float-repr/Python/modsupport.c
==============================================================================
--- python/branches/py3k-short-float-repr/Python/modsupport.c	(original)
+++ python/branches/py3k-short-float-repr/Python/modsupport.c	Sun Apr 5 01:04:14 2009
@@ -289,7 +289,7 @@
 		{
 			char p[1];
 			p[0] = (char)va_arg(*p_va, int);
-			return PyUnicode_FromStringAndSize(p, 1);
+			return PyBytes_FromStringAndSize(p, 1);
 		}
 		case 'C':
 		{
Modified: python/branches/py3k-short-float-repr/Python/pystrtod.c
==============================================================================
--- python/branches/py3k-short-float-repr/Python/pystrtod.c	(original)
+++ python/branches/py3k-short-float-repr/Python/pystrtod.c	Sun Apr 5 01:04:14 2009
@@ -378,7 +378,7 @@
 	/* At this point, p points just past the right-most character we
 	 want to format. We need to add the grouping string for the
 	 characters between buffer and p. */
-	return _PyBytes_InsertThousandsGrouping(buffer, len, p-buffer,
+	return _PyBytes_InsertThousandsGroupingLocale(buffer, len, p-buffer,
 						buf_size, NULL, 1);
 }
 
Modified: python/branches/py3k-short-float-repr/Python/pythonrun.c
==============================================================================
--- python/branches/py3k-short-float-repr/Python/pythonrun.c	(original)
+++ python/branches/py3k-short-float-repr/Python/pythonrun.c	Sun Apr 5 01:04:14 2009
@@ -1011,6 +1011,8 @@
 		parser_flags |= PyPARSE_DONT_IMPLY_DEDENT;
 	if (flags->cf_flags & PyCF_IGNORE_COOKIE)
 		parser_flags |= PyPARSE_IGNORE_COOKIE;
+	if (flags->cf_flags & CO_FUTURE_BARRY_AS_BDFL)
+		parser_flags |= PyPARSE_BARRY_AS_BDFL;
 	return parser_flags;
 }
 
@@ -1143,7 +1145,7 @@
 {
 	PyObject *m, *d, *v;
 	const char *ext;
-	int set_file_name = 0, ret;
+	int set_file_name = 0, ret, len;
 
 	m = PyImport_AddModule("__main__");
 	if (m == NULL)
@@ -1161,7 +1163,8 @@
 		set_file_name = 1;
 		Py_DECREF(f);
 	}
-	ext = filename + strlen(filename) - 4;
+	len = strlen(filename);
+	ext = filename + len - (len > 4 ? 4 : 0);
 	if (maybe_pyc_file(fp, filename, ext, closeit)) {
 		/* Try to run a pyc file. First, re-open in binary */
 		if (closeit)
@@ -2006,6 +2009,7 @@
 Py_FatalError(const char *msg)
 {
 	fprintf(stderr, "Fatal Python error: %s\n", msg);
+	fflush(stderr); /* it helps in Windows debug build */
 	if (PyErr_Occurred()) {
 		PyErr_Print();
 	}
Modified: python/branches/py3k-short-float-repr/Python/symtable.c
==============================================================================
--- python/branches/py3k-short-float-repr/Python/symtable.c	(original)
+++ python/branches/py3k-short-float-repr/Python/symtable.c	Sun Apr 5 01:04:14 2009
@@ -377,8 +377,9 @@
 
 /* Decide on scope of name, given flags.
 
- The dicts passed in as arguments are modified as necessary.
- ste is passed so that flags can be updated.
+ The namespace dictionaries may be modified to record information
+ about the new name. For example, a new global will add an entry to
+ global. A name that was global can be changed to local.
 */
 
 static int 
@@ -454,7 +455,7 @@
 	 explicit? It could also be global implicit.
 	 */
 	if (global && PySet_Contains(global, name)) {
-		SET_SCOPE(scopes, name, GLOBAL_EXPLICIT);
+		SET_SCOPE(scopes, name, GLOBAL_IMPLICIT);
 		return 1;
 	}
 	if (ste->ste_nested)
@@ -628,28 +629,56 @@
 } 
 
 /* Make final symbol table decisions for block of ste.
+
 Arguments:
 ste -- current symtable entry (input/output)
- bound -- set of variables bound in enclosing scopes (input)
+ bound -- set of variables bound in enclosing scopes (input). bound
+ is NULL for module blocks.
 free -- set of free variables in enclosed scopes (output)
 globals -- set of declared global variables in enclosing scopes (input)
+
+ The implementation uses two mutually recursive functions,
+ analyze_block() and analyze_child_block(). analyze_block() is
+ responsible for analyzing the individual names defined in a block.
+ analyze_child_block() prepares temporary namespace dictionaries
+ used to evaluated nested blocks.
+
+ The two functions exist because a child block should see the name
+ bindings of its enclosing blocks, but those bindings should not
+ propagate back to a parent block.
 */
 
 static int
+analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free, 
+		 PyObject *global, PyObject* child_free);
+
+static int
 analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free, 
 	 PyObject *global)
 {
 	PyObject *name, *v, *local = NULL, *scopes = NULL, *newbound = NULL;
-	PyObject *newglobal = NULL, *newfree = NULL;
+	PyObject *newglobal = NULL, *newfree = NULL, *allfree = NULL;
 	int i, success = 0;
 	Py_ssize_t pos = 0;
 
-	scopes = PyDict_New();
-	if (!scopes)
-		goto error;
-	local = PySet_New(NULL);
+	local = PySet_New(NULL); /* collect new names bound in block */
 	if (!local)
 		goto error;
+	scopes = PyDict_New(); /* collect scopes defined for each name */
+	if (!scopes)
+		goto error;
+
+	/* Allocate new global and bound variable dictionaries. These
+	 dictionaries hold the names visible in nested blocks. For
+	 ClassBlocks, the bound and global names are initialized
+	 before analyzing names, because class bindings aren't
+	 visible in methods. For other blocks, they are initialized
+	 after names are analyzed.
+	 */
+
+	/* TODO(jhylton): Package these dicts in a struct so that we
+	 can write reasonable helper functions?
+	*/
 	newglobal = PySet_New(NULL);
 	if (!newglobal)
 		goto error;
@@ -666,25 +695,22 @@
 	 this one.
 	 */
 	if (ste->ste_type == ClassBlock) {
+		/* Pass down known globals */
+		if (!PyNumber_InPlaceOr(newglobal, global))
+			goto error;
+		Py_DECREF(newglobal);
 		/* Pass down previously bound symbols */
 		if (bound) {
 			if (!PyNumber_InPlaceOr(newbound, bound))
 				goto error;
 			Py_DECREF(newbound);
 		}
-		/* Pass down known globals */
-		if (!PyNumber_InPlaceOr(newglobal, global))
-			goto error;
-		Py_DECREF(newglobal);
 	}
 
-	/* Analyze symbols in current scope */
-	assert(PySTEntry_Check(ste));
-	assert(PyDict_Check(ste->ste_symbols));
 	while (PyDict_Next(ste->ste_symbols, &pos, &name, &v)) {
 		long flags = PyLong_AS_LONG(v);
-		if (!analyze_name(ste, scopes, name, flags, bound, local, free,
-				 global))
+		if (!analyze_name(ste, scopes, name, flags,
+				 bound, local, free, global))
 			goto error;
 	}
 
@@ -716,19 +742,32 @@
 			goto error;
 	}
 
-	/* Recursively call analyze_block() on each child block */
+	/* Recursively call analyze_block() on each child block.
+
+	 newbound, newglobal now contain the names visible in
+	 nested blocks. The free variables in the children will
+	 be collected in allfree.
+	*/
+	allfree = PySet_New(NULL);
+	if (!allfree) 
+		goto error;
 	for (i = 0; i < PyList_GET_SIZE(ste->ste_children); ++i) {
 		PyObject *c = PyList_GET_ITEM(ste->ste_children, i);
 		PySTEntryObject* entry;
 		assert(c && PySTEntry_Check(c));
 		entry = (PySTEntryObject*)c;
-		if (!analyze_block(entry, newbound, newfree, newglobal))
+		if (!analyze_child_block(entry, newbound, newfree, newglobal,
+					 allfree))
 			goto error;
 		/* Check if any children have free variables */
 		if (entry->ste_free || entry->ste_child_free)
 			ste->ste_child_free = 1;
 	}
 
+	if (PyNumber_InPlaceOr(newfree, allfree) < 0)
+		goto error;
+	Py_DECREF(newfree);
+
 	/* Check if any local variables must be converted to cell variables */
 	if (ste->ste_type == FunctionBlock && !analyze_cells(scopes, newfree,
 							 NULL))
@@ -753,12 +792,52 @@
 	Py_XDECREF(newbound);
 	Py_XDECREF(newglobal);
 	Py_XDECREF(newfree);
+	Py_XDECREF(allfree);
 	if (!success)
 		assert(PyErr_Occurred());
 	return success;
 }
 
 static int
+analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free, 
+		 PyObject *global, PyObject* child_free)
+{
+	PyObject *temp_bound = NULL, *temp_global = NULL, *temp_free = NULL;
+
+	/* Copy the bound and global dictionaries.
+
+	 These dictionary are used by all blocks enclosed by the
+	 current block. The analyze_block() call modifies these
+	 dictionaries.
+
+	*/
+	temp_bound = PySet_New(bound);
+	if (!temp_bound)
+		goto error;
+	temp_free = PySet_New(free);
+	if (!temp_free)
+		goto error;
+	temp_global = PySet_New(global);
+	if (!temp_global)
+		goto error;
+
+	if (!analyze_block(entry, temp_bound, temp_free, temp_global))
+		goto error;
+	if (PyNumber_InPlaceOr(child_free, temp_free) < 0)
+		goto error;
+	Py_DECREF(child_free);
+	Py_DECREF(temp_bound);
+	Py_DECREF(temp_free);
+	Py_DECREF(temp_global);
+	return 1;
+ error:
+	Py_XDECREF(temp_bound);
+	Py_XDECREF(temp_free);
+	Py_XDECREF(temp_global);
+	return 0;
+}
+
+static int
 symtable_analyze(struct symtable *st)
 {
 	PyObject *free, *global;
Modified: python/branches/py3k-short-float-repr/README
==============================================================================
--- python/branches/py3k-short-float-repr/README	(original)
+++ python/branches/py3k-short-float-repr/README	Sun Apr 5 01:04:14 2009
@@ -1,7 +1,6 @@
-This is Python version 3.1 alpha 1
+This is Python version 3.1 alpha 2
 ==================================
 
-For notes specific to this release, see RELNOTES in this directory.
 Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
 Python Software Foundation.
 All rights reserved.
@@ -12,10 +11,6 @@
 changed considerably, and a lot of deprecated features have finally been
 removed.
 
-This is an ongoing project; the cleanup isn't expected to be complete
-until some time in 2008. In particular there are plans to reorganize
-the standard library namespace.
-
 
 Release Schedule
 ----------------
Deleted: python/branches/py3k-short-float-repr/RELNOTES
==============================================================================
--- python/branches/py3k-short-float-repr/RELNOTES	Sun Apr 5 01:04:14 2009
+++ (empty file)
@@ -1,29 +0,0 @@
-Python 3 Release Notes
-======================
-
-These release notes describe unfinished work, or important notes that Python 3
-adopters need to be aware of. This is not a complete list of changes for
-Python 3 -- for that, see Misc/NEWS.
-
-Please report bugs to http://bugs.python.org/
-
-The list of all known open issues for Python 3 can be found here:
-
-http://bugs.python.org/issue?%40search_text=&title=&%40columns=title&id=&%40columns=id&creation=&creator=&activity=&%40columns=activity&%40sort=activity&actor=&nosy=&type=&components=&versions=12&dependencies=&assignee=&keywords=&priority=&%40group=priority&status=1&%40columns=status&resolution=&%40pagesize=50&%40startwith=0&%40queryname=&%40old-queryname=&%40action=search
-
-
-Additional notes for Python 3
------------------------------
-
-* The bsddb3 package has been removed from the standard library. It is
- available as a separate distutils based package from the Python Cheeseshop.
- If you need bsddb3 support in Python 3, you can find it here:
-
- http://pypi.python.org/pypi/bsddb3
-
-* The email package needs quite a bit of work to make it consistent with
- respect to bytes and strings. There have been discussions on
- email-sig at python.org about where to go with the email package for Python 3,
- but this was not resolved in time for 3.0 final. With enough care though,
- the email package in Python 3 should be about as usable as it is with Python
- 2.
Modified: python/branches/py3k-short-float-repr/Tools/buildbot/test.bat
==============================================================================
--- python/branches/py3k-short-float-repr/Tools/buildbot/test.bat	(original)
+++ python/branches/py3k-short-float-repr/Tools/buildbot/test.bat	Sun Apr 5 01:04:14 2009
@@ -1,4 +1,4 @@
 @rem Used by the buildbot "test" step.
 cd PCbuild
-call rt.bat -d -q -uall -rw
+call rt.bat -d -q -uall -rw -n
 
Modified: python/branches/py3k-short-float-repr/Tools/msi/msi.py
==============================================================================
--- python/branches/py3k-short-float-repr/Tools/msi/msi.py	(original)
+++ python/branches/py3k-short-float-repr/Tools/msi/msi.py	Sun Apr 5 01:04:14 2009
@@ -1013,6 +1013,7 @@
 lib.glob("*.pem")
 lib.glob("*.pck")
 lib.add_file("readme.txt", src="README")
+ lib.add_file("zipdir.zip")
 if dir=='decimaltestdata':
 lib.glob("*.decTest")
 if dir=='output':
Modified: python/branches/py3k-short-float-repr/Tools/msi/msilib.py
==============================================================================
--- python/branches/py3k-short-float-repr/Tools/msi/msilib.py	(original)
+++ python/branches/py3k-short-float-repr/Tools/msi/msilib.py	Sun Apr 5 01:04:14 2009
@@ -5,7 +5,7 @@
 import win32com.client
 import pythoncom, pywintypes
 from win32com.client import constants
-import re, string, os, sets, glob, subprocess, sys, _winreg, struct
+import re, string, os, sets, glob, subprocess, sys, winreg, struct
 
 try:
 basestring
@@ -387,9 +387,9 @@
 (r"Software\Microsoft\Win32SDK\Directories", "Install Dir"),
 ]:
 try:
- key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, k)
- dir = _winreg.QueryValueEx(key, v)[0]
- _winreg.CloseKey(key)
+ key = winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, k)
+ dir = winreg.QueryValueEx(key, v)[0]
+ winreg.CloseKey(key)
 except (WindowsError, IndexError):
 continue
 cabarc = os.path.join(dir, r"Bin", "cabarc.exe")
Modified: python/branches/py3k-short-float-repr/Tools/scripts/reindent-rst.py
==============================================================================
--- python/branches/py3k-short-float-repr/Tools/scripts/reindent-rst.py	(original)
+++ python/branches/py3k-short-float-repr/Tools/scripts/reindent-rst.py	Sun Apr 5 01:04:14 2009
@@ -3,7 +3,7 @@
 # Make a reST file compliant to our pre-commit hook.
 # Currently just remove trailing whitespace.
 
-from __future__ import with_statement
+
 import sys, re, shutil
 
 ws_re = re.compile(r'\s+(\r?\n)$')
@@ -16,12 +16,12 @@
 lines = f.readlines()
 new_lines = [ws_re.sub(r'1円', line) for line in lines]
 if new_lines != lines:
- print 'Fixing %s...' % filename
+ print('Fixing %s...' % filename)
 shutil.copyfile(filename, filename + '.bak')
 with open(filename, 'wb') as f:
 f.writelines(new_lines)
- except Exception, err:
- print 'Cannot fix %s: %s' % (filename, err)
+ except Exception as err:
+ print('Cannot fix %s: %s' % (filename, err))
 rv = 1
 return rv
 
Modified: python/branches/py3k-short-float-repr/setup.py
==============================================================================
--- python/branches/py3k-short-float-repr/setup.py	(original)
+++ python/branches/py3k-short-float-repr/setup.py	Sun Apr 5 01:04:14 2009
@@ -1023,6 +1023,15 @@
 )
 libraries = []
 
+ elif platform.startswith('netbsd'):
+ macros = dict( # at least NetBSD 5
+ HAVE_SEM_OPEN=1,
+ HAVE_SEM_TIMEDWAIT=0,
+ HAVE_FD_TRANSFER=1,
+ HAVE_BROKEN_SEM_GETVALUE=1
+ )
+ libraries = []
+
 else: # Linux and other unices
 macros = dict(
 HAVE_SEM_OPEN=1,


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /