[Python-checkins] r77668 - in python/branches/py3k-cdecimal: Doc/c-api/init.rst Doc/library/2to3.rst Doc/library/email.generator.rst Doc/library/email.message.rst Doc/library/email.mime.rst Doc/library/gzip.rst Doc/library/importlib.rst Doc/library/inspect.rst Doc/library/math.rst Doc/library/os.rst Doc/library/re.rst Doc/library/stdtypes.rst Doc/library/unittest.rst Doc/library/weakref.rst Doc/library/zipimport.rst Doc/using/windows.rst Doc/whatsnew/2.7.rst Include/bytearrayobject.h Lib/_weakrefset.py Lib/cmd.py Lib/distutils/ccompiler.py Lib/distutils/tests/test_unixccompiler.py Lib/distutils/unixccompiler.py Lib/email/generator.py Lib/email/test/data/msg_45.txt Lib/email/test/test_email.py Lib/email/utils.py Lib/gzip.py Lib/idlelib/NEWS.txt Lib/logging/__init__.py Lib/pickle.py Lib/platform.py Lib/ssl.py Lib/test/crashers/bogus_code_obj.py Lib/test/floating_points.txt Lib/test/https_svn_python_org_root.pem Lib/test/pickletester.py Lib/test/regrtest.py Lib/test/test_bigmem.py Lib/test/test_binascii.py Lib/test/test_builtin.py Lib/test/test_bytes.py Lib/test/test_cgi.py Lib/test/test_cmd.py Lib/test/test_cmd_line.py Lib/test/test_cmd_line_script.py Lib/test/test_collections.py Lib/test/test_compile.py Lib/test/test_contains.py Lib/test/test_copyreg.py Lib/test/test_csv.py Lib/test/test_datetime.py Lib/test/test_dbm.py Lib/test/test_dbm_dumb.py Lib/test/test_dbm_gnu.py Lib/test/test_dbm_ndbm.py Lib/test/test_decimal.py Lib/test/test_defaultdict.py Lib/test/test_deque.py Lib/test/test_descr.py Lib/test/test_dict.py Lib/test/test_dictviews.py Lib/test/test_exceptions.py Lib/test/test_float.py Lib/test/test_funcattrs.py Lib/test/test_glob.py Lib/test/test_gzip.py Lib/test/test_hashlib.py Lib/test/test_http_cookiejar.py Lib/test/test_import.py Lib/test/test_index.py Lib/test/test_inspect.py Lib/test/test_ioctl.py Lib/test/test_iter.py Lib/test/test_logging.py Lib/test/test_long.py Lib/test/test_mmap.py Lib/test/test_multiprocessing.py Lib/test/test_os.py Lib/test/test_peepholer.py Lib/test/test_pep352.py Lib/test/test_poplib.py Lib/test/test_posix.py Lib/test/test_posixpath.py Lib/test/test_pwd.py Lib/test/test_pyclbr.py Lib/test/test_pydoc.py Lib/test/test_raise.py Lib/test/test_random.py Lib/test/test_range.py Lib/test/test_re.py Lib/test/test_reprlib.py Lib/test/test_runpy.py Lib/test/test_sax.py Lib/test/test_scope.py Lib/test/test_set.py Lib/test/test_site.py Lib/test/test_socket.py Lib/test/test_strtod.py Lib/test/test_structseq.py Lib/test/test_subprocess.py Lib/test/test_sys.py Lib/test/test_tarfile.py Lib/test/test_telnetlib.py Lib/test/test_tempfile.py Lib/test/test_threading.py Lib/test/test_threading_local.py Lib/test/test_traceback.py Lib/test/test_types.py Lib/test/test_unicode.py Lib/test/test_unicode_file.py Lib/test/test_unicodedata.py Lib/test/test_unittest.py Lib/test/test_urllib.py Lib/test/test_urllib2.py Lib/test/test_userdict.py Lib/test/test_warnings.py Lib/test/test_wave.py Lib/test/test_weakref.py Lib/test/test_weakset.py Lib/test/test_wsgiref.py Lib/test/test_zipfile.py Lib/test/test_zipimport.py Lib/test/test_zipimport_support.py Lib/turtle.py Lib/unittest/__init__.py Lib/wave.py Lib/weakref.py Mac/Resources/app/Info.plist.in Makefile.pre.in Misc/ACKS Misc/NEWS Misc/RPM/python-3.2.spec Misc/build.sh Misc/developers.txt Misc/gdbinit Modules/_ctypes/libffi/fficonfig.py.in Modules/_hashopenssl.c Modules/_pickle.c Modules/_sre.c Modules/_testcapimodule.c Modules/binascii.c Modules/posixmodule.c Objects/bytearrayobject.c Objects/bytesobject.c Objects/longobject.c Objects/stringlib/count.h Objects/stringlib/ctype.h Objects/stringlib/fastsearch.h Objects/stringlib/find.h Objects/stringlib/partition.h Objects/stringlib/split.h Objects/stringlib/stringdefs.h Objects/stringlib/transmogrify.h Objects/stringlib/unicodedefs.h Objects/unicodeobject.c PC/VS8.0/pythoncore.vcproj PCbuild/pythoncore.vcproj Python/dtoa.c Python/peephole.c Tools/ccbench Tools/iobench setup.py
mark.dickinson
python-checkins at python.org
Thu Jan 21 20:32:25 CET 2010
Author: mark.dickinson
Date: Thu Jan 21 20:32:23 2010
New Revision: 77668
Log:
Merged revisions 77341,77355,77363,77365,77373,77375,77380,77383,77387-77389,77393-77396,77398-77399,77405,77407-77408,77414,77417,77427,77429,77433,77437,77440-77441,77444,77447,77449,77452,77457,77459,77462,77464-77465,77468,77471,77474,77476,77479,77485,77494,77498,77501,77508,77516,77520-77521,77523,77529,77535,77539,77542-77543,77549,77551,77568,77571,77576,77579,77583,77590,77597,77602,77604 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r77341 | mark.dickinson | 2010-01-07 09:31:48 +0000 (Thu, 07 Jan 2010) | 9 lines
Merged revisions 77339 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77339 | mark.dickinson | 2010-01-07 09:28:29 +0000 (Thu, 07 Jan 2010) | 1 line
Eric Smith was missing fro m the issue 7117 whatsnew attribution.
........
................
r77355 | antoine.pitrou | 2010-01-07 17:57:31 +0000 (Thu, 07 Jan 2010) | 18 lines
Merged revisions 77352-77354 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77352 | antoine.pitrou | 2010-01-07 18:46:49 +0100 (jeu., 07 janv. 2010) | 5 lines
Issue #7455: Fix possible crash in cPickle on invalid input. Patch by
Florent Xicluna.
........
r77353 | antoine.pitrou | 2010-01-07 18:49:37 +0100 (jeu., 07 janv. 2010) | 3 lines
Fix attribution. Florent actually repackaged and reviewed Victor's patch (sorry!).
........
r77354 | antoine.pitrou | 2010-01-07 18:54:10 +0100 (jeu., 07 janv. 2010) | 3 lines
Fix reattribution mistake when fixing attribution mistake!
........
................
r77363 | mark.dickinson | 2010-01-08 16:55:38 +0000 (Fri, 08 Jan 2010) | 8 lines
Blocked revisions 77362 via svnmerge
........
r77362 | mark.dickinson | 2010-01-08 16:53:56 +0000 (Fri, 08 Jan 2010) | 1 line
Backport some float repr tests that were missed in issue 7117.
........
................
r77365 | antoine.pitrou | 2010-01-08 17:54:23 +0000 (Fri, 08 Jan 2010) | 3 lines
Issue #7105: Make WeakKeyDictionary and WeakValueDictionary robust against
the destruction of weakref'ed objects while iterating.
................
r77373 | antoine.pitrou | 2010-01-08 19:22:50 +0000 (Fri, 08 Jan 2010) | 11 lines
Blocked revisions 77370 via svnmerge
........
r77370 | antoine.pitrou | 2010-01-08 20:20:17 +0100 (ven., 08 janv. 2010) | 5 lines
Issue #7092: Remove py3k warning when importing cPickle. 2to3 handles
renaming of `cPickle` to `pickle`. The warning was annoying since there's
no alternative to cPickle if you care about performance. Patch by Florent
Xicluna.
........
................
r77375 | antoine.pitrou | 2010-01-08 19:42:10 +0000 (Fri, 08 Jan 2010) | 10 lines
Merged revisions 77374 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77374 | antoine.pitrou | 2010-01-08 20:39:04 +0100 (ven., 08 janv. 2010) | 4 lines
Remove obsolete warning filters in regrtest.py (from issue #7092 -- patch by
Florent Xicluna).
........
................
r77380 | tarek.ziade | 2010-01-08 23:57:53 +0000 (Fri, 08 Jan 2010) | 9 lines
Merged revisions 77377 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77377 | tarek.ziade | 2010-01-09 00:42:23 +0100 (Sat, 09 Jan 2010) | 1 line
Fixed #7617: all flavors of gcc should be recognized now
........
................
r77383 | georg.brandl | 2010-01-09 09:48:46 +0000 (Sat, 09 Jan 2010) | 9 lines
Merged revisions 77382 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77382 | georg.brandl | 2010-01-09 10:47:11 +0100 (Sa, 09 Jan 2010) | 1 line
#7422: make it clear that getargspec() only works on Python functions.
........
................
r77387 | benjamin.peterson | 2010-01-09 17:36:21 +0000 (Sat, 09 Jan 2010) | 12 lines
Blocked revisions 77384,77386 via svnmerge
........
r77384 | benjamin.peterson | 2010-01-09 10:34:06 -0600 (Sat, 09 Jan 2010) | 1 line
bump version to 2.7a2
........
r77386 | benjamin.peterson | 2010-01-09 11:30:31 -0600 (Sat, 09 Jan 2010) | 1 line
post release version adjustment
........
................
r77388 | benjamin.peterson | 2010-01-09 17:45:42 +0000 (Sat, 09 Jan 2010) | 25 lines
Blocked revisions 77227,77256,77260,77368-77369 via svnmerge
........
r77227 | martin.v.loewis | 2010-01-02 03:53:18 -0600 (Sat, 02 Jan 2010) | 1 line
Make script work with 2.5.
........
r77256 | georg.brandl | 2010-01-02 16:55:55 -0600 (Sat, 02 Jan 2010) | 1 line
Fix typo.
........
r77260 | gregory.p.smith | 2010-01-02 18:43:02 -0600 (Sat, 02 Jan 2010) | 2 lines
make setup.py similar to py3k's when reporting on _hashlib as missing or not.
........
r77368 | senthil.kumaran | 2010-01-08 12:41:40 -0600 (Fri, 08 Jan 2010) | 1 line
Fixing - Issue7026 - RuntimeError: dictionary changed size during iteration. Patch by flox
........
r77369 | senthil.kumaran | 2010-01-08 13:04:16 -0600 (Fri, 08 Jan 2010) | 4 lines
Reverting the Revision: 77368. I committed Flox's big patch for tests by
mistake. ( It may come in for sure tough)
........
................
r77389 | benjamin.peterson | 2010-01-09 18:45:30 +0000 (Sat, 09 Jan 2010) | 25 lines
Merged revisions 77209,77229,77359-77360,77371 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77209 | georg.brandl | 2010-01-01 07:07:05 -0600 (Fri, 01 Jan 2010) | 1 line
More yearly updates.
........
r77229 | georg.brandl | 2010-01-02 06:35:01 -0600 (Sat, 02 Jan 2010) | 1 line
Fix casing.
........
r77359 | georg.brandl | 2010-01-07 14:54:45 -0600 (Thu, 07 Jan 2010) | 1 line
Fix description for Py_GetPath(); it sounded like it always returned sys.path.
........
r77360 | georg.brandl | 2010-01-07 15:48:47 -0600 (Thu, 07 Jan 2010) | 1 line
#7653: clarify how the PythonPath registry key should look like.
........
r77371 | senthil.kumaran | 2010-01-08 13:20:25 -0600 (Fri, 08 Jan 2010) | 3 lines
Fix for Issue7026. For the Error - RuntimeError: dictionary changed size during iteration
........
................
r77393 | benjamin.peterson | 2010-01-09 18:53:06 +0000 (Sat, 09 Jan 2010) | 57 lines
Merged revisions 77185-77188,77262,77313,77317,77331-77333,77337-77338 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77185 | andrew.kuchling | 2009-12-31 10:17:05 -0600 (Thu, 31 Dec 2009) | 1 line
Add some items
........
r77186 | benjamin.peterson | 2009-12-31 10:28:24 -0600 (Thu, 31 Dec 2009) | 1 line
update expat comment
........
r77187 | andrew.kuchling | 2009-12-31 10:38:53 -0600 (Thu, 31 Dec 2009) | 1 line
Add various items
........
r77188 | benjamin.peterson | 2009-12-31 10:49:37 -0600 (Thu, 31 Dec 2009) | 1 line
add another advancement
........
r77262 | andrew.kuchling | 2010-01-02 19:15:21 -0600 (Sat, 02 Jan 2010) | 1 line
Add a few items
........
r77313 | benjamin.peterson | 2010-01-04 18:04:19 -0600 (Mon, 04 Jan 2010) | 1 line
add a test about hashing array.array
........
r77317 | georg.brandl | 2010-01-05 12:14:52 -0600 (Tue, 05 Jan 2010) | 1 line
Add Stefan.
........
r77331 | georg.brandl | 2010-01-06 11:43:06 -0600 (Wed, 06 Jan 2010) | 1 line
Small fixes to test_cmd: fix signature of do_shell, remove duplicate import, add option to run the custom Cmd class.
........
r77332 | georg.brandl | 2010-01-06 12:02:16 -0600 (Wed, 06 Jan 2010) | 7 lines
#5991: let completion for the "help" command include help topics.
This also simplifies the Cmd.get_names() method implementation; it was written
at a time where dir() didn't consider base class attributes.
........
r77333 | georg.brandl | 2010-01-06 12:26:08 -0600 (Wed, 06 Jan 2010) | 1 line
#5950: document that zip files with comments are unsupported in zipimport.
........
r77337 | r.david.murray | 2010-01-06 21:09:08 -0600 (Wed, 06 Jan 2010) | 3 lines
Add -W to the 'basics', 'opt', and 'all' test runs so that we get verbose
information if a failure happens.
........
r77338 | r.david.murray | 2010-01-06 22:04:28 -0600 (Wed, 06 Jan 2010) | 2 lines
Fix inadvertent checkin of debug line.
........
................
r77394 | alexandre.vassalotti | 2010-01-09 20:35:09 +0000 (Sat, 09 Jan 2010) | 2 lines
Issue #1023290: Added API for the conversion of longs to bytes and vice-versa.
................
r77395 | benjamin.peterson | 2010-01-09 21:45:28 +0000 (Sat, 09 Jan 2010) | 2 lines
Python strings ending with '\0' should not be equivalent to their C counterparts in PyUnicode_CompareWithASCIIString
................
r77396 | benjamin.peterson | 2010-01-09 21:50:11 +0000 (Sat, 09 Jan 2010) | 1 line
simplify string comparison of from_bytes/to_bytes
................
r77398 | alexandre.vassalotti | 2010-01-09 22:14:46 +0000 (Sat, 09 Jan 2010) | 6 lines
Issue #6688: Optimize PyBytes_FromObject().
- Add special-cases for list and tuple objects.
- Use _PyObject_LengthHint() instead of an arbitrary value for the
size of the initial buffer of the returned object.
................
r77399 | georg.brandl | 2010-01-09 22:39:42 +0000 (Sat, 09 Jan 2010) | 1 line
Remove redundant brackets in signatures.
................
r77405 | martin.v.loewis | 2010-01-10 10:31:46 +0000 (Sun, 10 Jan 2010) | 9 lines
Merged revisions 77403 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77403 | martin.v.loewis | 2010-01-10 11:29:54 +0100 (So, 10 Jan 2010) | 2 lines
Update root certificate to CAcert.
........
................
r77407 | mark.dickinson | 2010-01-10 11:27:39 +0000 (Sun, 10 Jan 2010) | 9 lines
Blocked revisions 77391 via svnmerge
........
r77391 | mark.dickinson | 2010-01-09 18:50:50 +0000 (Sat, 09 Jan 2010) | 3 lines
Issue #7532: Add additional slicing test cases for new- and old-style
classes. Patch by Florent Xicluna.
........
................
r77408 | mark.dickinson | 2010-01-10 11:59:43 +0000 (Sun, 10 Jan 2010) | 4 lines
Issue #7532: Expanded tests for extended slicing. This is a forward
port of r77391 to py3k, along with some additional tests and cleanup.
Patch by Florent Xicluna.
................
r77414 | senthil.kumaran | 2010-01-10 17:45:52 +0000 (Sun, 10 Jan 2010) | 9 lines
Merged revisions 77411 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77411 | senthil.kumaran | 2010-01-10 23:05:05 +0530 (Sun, 10 Jan 2010) | 2 lines
Fixed issue7648 - test_urllib2 fails on Windows if not run from C:
........
................
r77417 | r.david.murray | 2010-01-10 19:18:27 +0000 (Sun, 10 Jan 2010) | 10 lines
Merged revisions 77412 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77412 | r.david.murray | 2010-01-10 12:41:28 -0500 (Sun, 10 Jan 2010) | 3 lines
Issue #7119: document that a program-generated Message object
tree may be mutated when serialized.
........
................
r77427 | tarek.ziade | 2010-01-11 23:15:52 +0000 (Mon, 11 Jan 2010) | 9 lines
Merged revisions 77424 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77424 | tarek.ziade | 2010-01-11 23:50:29 +0100 (Mon, 11 Jan 2010) | 1 line
Fixed #5372: .o files are now always rebuilt because file age test don't work in some case
........
................
r77429 | alexandre.vassalotti | 2010-01-11 23:21:10 +0000 (Mon, 11 Jan 2010) | 16 lines
Blocked revisions 77400,77422,77428 via svnmerge
........
r77400 | alexandre.vassalotti | 2010-01-09 18:35:54 -0500 (Sat, 09 Jan 2010) | 2 lines
Issue #2335: Backport set literals syntax from Python 3.x.
........
r77422 | alexandre.vassalotti | 2010-01-11 17:36:12 -0500 (Mon, 11 Jan 2010) | 2 lines
Issue #2333: Backport set and dict comprehensions syntax.
........
r77428 | alexandre.vassalotti | 2010-01-11 18:17:10 -0500 (Mon, 11 Jan 2010) | 2 lines
Issue #1967: Backport dictionary views.
........
................
r77433 | tarek.ziade | 2010-01-11 23:47:51 +0000 (Mon, 11 Jan 2010) | 9 lines
Merged revisions 77431 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77431 | tarek.ziade | 2010-01-12 00:41:32 +0100 (Tue, 12 Jan 2010) | 1 line
module cleanup
........
................
r77437 | alexandre.vassalotti | 2010-01-12 01:23:09 +0000 (Tue, 12 Jan 2010) | 2 lines
Issue #7382: Fix bytes.__getnewargs__.
................
r77440 | alexandre.vassalotti | 2010-01-12 01:49:31 +0000 (Tue, 12 Jan 2010) | 2 lines
Simplified long coding in pickle.py.
................
r77441 | alexandre.vassalotti | 2010-01-12 01:51:09 +0000 (Tue, 12 Jan 2010) | 8 lines
Blocked revisions 77438 via svnmerge
........
r77438 | alexandre.vassalotti | 2010-01-11 20:34:43 -0500 (Mon, 11 Jan 2010) | 2 lines
Fixed repr of dictionary views.
........
................
r77444 | ezio.melotti | 2010-01-12 04:03:11 +0000 (Tue, 12 Jan 2010) | 8 lines
Blocked revisions 77442 via svnmerge
........
r77442 | ezio.melotti | 2010-01-12 05:32:05 +0200 (Tue, 12 Jan 2010) | 1 line
#5827: make sure that normpath preserves unicode
........
................
r77447 | alexandre.vassalotti | 2010-01-12 18:38:14 +0000 (Tue, 12 Jan 2010) | 9 lines
Merged revisions 77445 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77445 | alexandre.vassalotti | 2010-01-12 13:25:33 -0500 (Tue, 12 Jan 2010) | 2 lines
Added documentation for dictionary views fixer.
........
................
r77449 | antoine.pitrou | 2010-01-12 22:05:42 +0000 (Tue, 12 Jan 2010) | 9 lines
Merged revisions 77448 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77448 | antoine.pitrou | 2010-01-12 23:02:10 +0100 (mar., 12 janv. 2010) | 3 lines
Issue #7654: enable additional bytes/bytearray tests. Patch by Florent Xicluna.
........
................
r77452 | mark.dickinson | 2010-01-12 23:04:19 +0000 (Tue, 12 Jan 2010) | 23 lines
Merged revisions 77410,77421,77450-77451 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77410 | mark.dickinson | 2010-01-10 13:06:31 +0000 (Sun, 10 Jan 2010) | 1 line
Remove unused BCinfo fields and an unused macro.
........
r77421 | mark.dickinson | 2010-01-11 17:15:13 +0000 (Mon, 11 Jan 2010) | 1 line
Change a variable type to avoid signed overflow; replace repeated '19999' constant by a define.
........
r77450 | mark.dickinson | 2010-01-12 22:23:56 +0000 (Tue, 12 Jan 2010) | 4 lines
Issue #7632: Fix a problem with _Py_dg_strtod that could lead to
crashes in debug builds, for certain long numeric strings
corresponding to subnormal values.
........
r77451 | mark.dickinson | 2010-01-12 22:55:51 +0000 (Tue, 12 Jan 2010) | 2 lines
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
........
................
r77457 | ezio.melotti | 2010-01-13 00:28:37 +0000 (Wed, 13 Jan 2010) | 9 lines
Merged revisions 77455 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77455 | ezio.melotti | 2010-01-13 02:25:03 +0200 (Wed, 13 Jan 2010) | 1 line
#7685: typo
........
................
r77459 | benjamin.peterson | 2010-01-13 03:49:50 +0000 (Wed, 13 Jan 2010) | 1 line
use floor division where needed #7681
................
r77462 | antoine.pitrou | 2010-01-13 08:07:53 +0000 (Wed, 13 Jan 2010) | 11 lines
Merged revisions 77461 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77461 | antoine.pitrou | 2010-01-13 08:55:48 +0100 (mer., 13 janv. 2010) | 5 lines
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
methods of bytes, bytearray and unicode objects by using a common
implementation based on stringlib's fast search. Patch by Florent Xicluna.
........
................
r77464 | antoine.pitrou | 2010-01-13 08:58:08 +0000 (Wed, 13 Jan 2010) | 9 lines
Merged revisions 77463 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77463 | antoine.pitrou | 2010-01-13 09:55:20 +0100 (mer., 13 janv. 2010) | 3 lines
Fix Windows build (re r77461)
........
................
r77465 | antoine.pitrou | 2010-01-13 09:19:15 +0000 (Wed, 13 Jan 2010) | 3 lines
svnmerge duplicated contents of Objects/stringlib/split.h
................
r77468 | antoine.pitrou | 2010-01-13 12:04:20 +0000 (Wed, 13 Jan 2010) | 18 lines
Note: I'm merging these changes out of consistency, but they don't seem
to be needed in py3k (except perhaps for non-utf8 paths).
Merged revisions 77466-77467 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77466 | antoine.pitrou | 2010-01-13 12:47:49 +0100 (mer., 13 janv. 2010) | 5 lines
Issue #7661: Allow ctypes to be built from a non-ASCII directory path.
Patch by Florent Xicluna.
........
r77467 | antoine.pitrou | 2010-01-13 12:57:42 +0100 (mer., 13 janv. 2010) | 3 lines
Use `with`
........
................
r77471 | antoine.pitrou | 2010-01-13 14:19:12 +0000 (Wed, 13 Jan 2010) | 13 lines
Merged revisions 77469-77470 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77469 | antoine.pitrou | 2010-01-13 14:43:37 +0100 (mer., 13 janv. 2010) | 3 lines
Test commit to try to diagnose failures of the IA-64 buildbot
........
r77470 | antoine.pitrou | 2010-01-13 15:01:26 +0100 (mer., 13 janv. 2010) | 3 lines
Sanitize bloom filter macros
........
................
r77474 | antoine.pitrou | 2010-01-13 14:37:26 +0000 (Wed, 13 Jan 2010) | 14 lines
Merged revisions 77472-77473 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77472 | antoine.pitrou | 2010-01-13 15:32:10 +0100 (mer., 13 janv. 2010) | 5 lines
Issue #2846: Add support for gzip.GzipFile reading zero-padded files.
Patch by Brian Curtin.
........
r77473 | antoine.pitrou | 2010-01-13 15:32:51 +0100 (mer., 13 janv. 2010) | 3 lines
Add ACKS entry for r77472.
........
................
r77476 | antoine.pitrou | 2010-01-13 15:03:39 +0000 (Wed, 13 Jan 2010) | 10 lines
Merged revisions 77475 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77475 | antoine.pitrou | 2010-01-13 16:02:13 +0100 (mer., 13 janv. 2010) | 4 lines
Issue #7625: Add more tests that bytearray methods return new objects,
even if identical. Patch by Florent Xicluna (again).
........
................
r77479 | brett.cannon | 2010-01-13 19:21:00 +0000 (Wed, 13 Jan 2010) | 1 line
Fix the wrong numbering of a PEP.
................
r77485 | skip.montanaro | 2010-01-14 01:14:50 +0000 (Thu, 14 Jan 2010) | 2 lines
Make similar changes to 3.x version.
................
r77494 | mark.dickinson | 2010-01-14 15:37:49 +0000 (Thu, 14 Jan 2010) | 41 lines
Merged revisions 77477-77478,77481-77483,77490-77493 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77477 | mark.dickinson | 2010-01-13 18:21:53 +0000 (Wed, 13 Jan 2010) | 1 line
Add comments explaining the role of the bigcomp function in dtoa.c.
........
r77478 | mark.dickinson | 2010-01-13 19:02:37 +0000 (Wed, 13 Jan 2010) | 1 line
Clarify that sulp expects a nonnegative input, but that +0.0 is fine.
........
r77481 | mark.dickinson | 2010-01-13 20:55:03 +0000 (Wed, 13 Jan 2010) | 1 line
Simplify and annotate the bigcomp function, removing unused special cases.
........
r77482 | mark.dickinson | 2010-01-13 22:15:53 +0000 (Wed, 13 Jan 2010) | 1 line
Fix buggy comparison: LHS of comparison was being treated as unsigned.
........
r77483 | mark.dickinson | 2010-01-13 22:20:10 +0000 (Wed, 13 Jan 2010) | 1 line
More dtoa.c cleanup; remove the need for bc.dplen, bc.dp0 and bc.dp1.
........
r77490 | mark.dickinson | 2010-01-14 13:02:36 +0000 (Thu, 14 Jan 2010) | 1 line
Fix off-by-one error introduced in r77483. I have a test for this, but it currently fails due to a different dtoa.c bug; I'll add the test once that bug is fixed.
........
r77491 | mark.dickinson | 2010-01-14 13:14:49 +0000 (Thu, 14 Jan 2010) | 1 line
Issue 7632: fix a dtoa.c bug (bug 6) causing incorrect rounding. Tests to follow.
........
r77492 | mark.dickinson | 2010-01-14 14:40:20 +0000 (Thu, 14 Jan 2010) | 1 line
Issue 7632: fix incorrect rounding for long input strings with values very close to a power of 2. (See Bug 4 in the tracker discussion.)
........
r77493 | mark.dickinson | 2010-01-14 15:22:33 +0000 (Thu, 14 Jan 2010) | 1 line
Issue #7632: add tests for bugs fixed so far.
........
................
r77498 | antoine.pitrou | 2010-01-14 16:33:34 +0000 (Thu, 14 Jan 2010) | 15 lines
Merge note: only the tests have been kept here, since the rest was already
a backport.
Merged revisions 77497 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77497 | antoine.pitrou | 2010-01-14 17:27:09 +0100 (jeu., 14 janv. 2010) | 5 lines
Issue #7703: Add support for the new buffer API to functions of the
binascii module. Backported from py3k by Florent Xicluna, with some
additional tests.
........
................
r77501 | antoine.pitrou | 2010-01-14 17:34:48 +0000 (Thu, 14 Jan 2010) | 10 lines
Merged revisions 77499 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77499 | antoine.pitrou | 2010-01-14 18:25:24 +0100 (jeu., 14 janv. 2010) | 4 lines
Issue #3299: Fix possible crash in the _sre module when given bad
argument values in debug mode. Patch by Victor Stinner.
........
................
r77508 | antoine.pitrou | 2010-01-15 00:27:43 +0000 (Fri, 15 Jan 2010) | 10 lines
Merged revisions 77506 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77506 | antoine.pitrou | 2010-01-15 01:18:00 +0100 (ven., 15 janv. 2010) | 4 lines
Issue #7701: Fix crash in binascii.b2a_uu() in debug mode when given a
1-byte argument. Patch by Victor Stinner.
........
................
r77516 | sean.reifschneider | 2010-01-16 04:35:26 +0000 (Sat, 16 Jan 2010) | 1 line
issue5063: Fixes for building RPM on CentOS plus misc .spec file enhancements.
................
r77520 | georg.brandl | 2010-01-16 14:41:21 +0000 (Sat, 16 Jan 2010) | 1 line
Remove L suffix for integers.
................
r77521 | ezio.melotti | 2010-01-16 14:46:27 +0000 (Sat, 16 Jan 2010) | 1 line
remove obsolete sentence
................
r77523 | ezio.melotti | 2010-01-16 15:09:48 +0000 (Sat, 16 Jan 2010) | 1 line
Fixed crasher. Patch by Florent Xicluna.
................
r77529 | antoine.pitrou | 2010-01-16 17:55:52 +0000 (Sat, 16 Jan 2010) | 10 lines
Merged revisions 77528 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77528 | antoine.pitrou | 2010-01-16 18:45:56 +0100 (sam., 16 janv. 2010) | 4 lines
Followup to #7703: a2b_hqx() didn't follow the new buffer API (neither in trunk
nor in py3k). Patch by Florent Xicluna as well as additional tests.
........
................
r77535 | mark.dickinson | 2010-01-16 18:10:25 +0000 (Sat, 16 Jan 2010) | 21 lines
Merged revisions 77519,77530,77533 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77519 | mark.dickinson | 2010-01-16 10:44:00 +0000 (Sat, 16 Jan 2010) | 5 lines
Issue #7632: Fix a serious wrong output bug for string -> float conversion.
Also remove some now unused variables, and add comments clarifying the
possible outputs of the parsing section of _Py_dg_strtod. Thanks
Eric Smith for reviewing.
........
r77530 | mark.dickinson | 2010-01-16 17:57:49 +0000 (Sat, 16 Jan 2010) | 3 lines
Issue #7632: Fix one more case of incorrect rounding for str -> float
conversion (see bug 5 in the issue tracker).
........
r77533 | mark.dickinson | 2010-01-16 18:06:17 +0000 (Sat, 16 Jan 2010) | 1 line
Fix multiple uses of variable 'L' in _Py_dg_strtod, where one use requires an unsigned long and the other a signed long. See also r77421.
........
................
r77539 | antoine.pitrou | 2010-01-16 18:15:15 +0000 (Sat, 16 Jan 2010) | 4 lines
Remove duplicated line when merging (it was even valid C!).
Thanks Florent for noticing.
................
r77542 | r.david.murray | 2010-01-16 18:30:03 +0000 (Sat, 16 Jan 2010) | 18 lines
Merged revisions 77517,77525 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
Merge adds an additional test for as_string with a maxheaderlen specified.
........
r77517 | r.david.murray | 2010-01-16 00:15:17 -0500 (Sat, 16 Jan 2010) | 6 lines
Issue #1670765: Prevent email.generator.Generator from re-wrapping
headers in multipart/signed MIME parts, which fixes one of the sources of
invalid modifications to such parts by Generator. Patch and tests by
Martin von Gagern.
........
r77525 | r.david.murray | 2010-01-16 11:08:32 -0500 (Sat, 16 Jan 2010) | 2 lines
Fix issue number in comment.
........
................
r77543 | antoine.pitrou | 2010-01-16 18:37:38 +0000 (Sat, 16 Jan 2010) | 9 lines
Issue #6690: Optimize the bytecode for expressions such as `x in {1, 2, 3}`,
where the right hand operand is a set of constants, by turning the set into
a frozenset and pre-building it as a constant. The comparison operation
is made against the constant instead of building a new set each time it is
executed (a similar optimization already existed which turned a list of
constants into a pre-built tuple). Patch and additional tests by Dave
Malcolm.
................
r77549 | ezio.melotti | 2010-01-16 19:40:06 +0000 (Sat, 16 Jan 2010) | 9 lines
Merged revisions 77548 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77548 | ezio.melotti | 2010-01-16 21:36:42 +0200 (Sat, 16 Jan 2010) | 1 line
remove wrong markup
........
................
r77551 | mark.dickinson | 2010-01-16 20:34:30 +0000 (Sat, 16 Jan 2010) | 9 lines
Merged revisions 77550 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77550 | mark.dickinson | 2010-01-16 20:33:02 +0000 (Sat, 16 Jan 2010) | 1 line
Add better error reporting for MemoryErrors caused by str->float conversions.
........
................
r77568 | mark.dickinson | 2010-01-17 11:13:30 +0000 (Sun, 17 Jan 2010) | 9 lines
Merged revisions 77566 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77566 | mark.dickinson | 2010-01-17 11:10:03 +0000 (Sun, 17 Jan 2010) | 1 line
Increase number of strtod tests slightly, to make it more likely that a memory leak is detected.
........
................
r77571 | antoine.pitrou | 2010-01-17 12:16:23 +0000 (Sun, 17 Jan 2010) | 4 lines
Issue #7561: Fix crashes when using bytearray objects with the posix
module.
................
r77576 | antoine.pitrou | 2010-01-17 12:38:54 +0000 (Sun, 17 Jan 2010) | 12 lines
Merged revisions 77573 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77573 | antoine.pitrou | 2010-01-17 13:26:20 +0100 (dim., 17 janv. 2010) | 6 lines
Issue #7561: Operations on empty bytearrays (such as `int(bytearray())`)
could crash in many places because of the PyByteArray_AS_STRING() macro
returning NULL. The macro now returns a statically allocated empty
string instead.
........
................
r77579 | mark.dickinson | 2010-01-17 14:39:12 +0000 (Sun, 17 Jan 2010) | 9 lines
Merged revisions 77578 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77578 | mark.dickinson | 2010-01-17 13:37:57 +0000 (Sun, 17 Jan 2010) | 2 lines
Issue #7632: Fix a memory leak in _Py_dg_strtod.
........
................
r77583 | antoine.pitrou | 2010-01-17 16:15:29 +0000 (Sun, 17 Jan 2010) | 9 lines
Merged revisions 77581 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77581 | antoine.pitrou | 2010-01-17 16:55:45 +0100 (dim., 17 janv. 2010) | 3 lines
Use PyAPI_DATA.
........
................
r77590 | mark.dickinson | 2010-01-17 21:02:55 +0000 (Sun, 17 Jan 2010) | 14 lines
Merged revisions 77589 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77589 | mark.dickinson | 2010-01-17 20:57:56 +0000 (Sun, 17 Jan 2010) | 7 lines
Issue #7632: When Py_USING_MEMORY_DEBUGGER is defined, disable the
private memory allocation scheme in dtoa.c, along with a piece of code
that caches powers of 5 for future use. This makes it easier to
detect dtoa.c memory leaks with Valgrind or similar tools.
Patch by Stefan Krah.
........
................
r77597 | ezio.melotti | 2010-01-18 09:15:14 +0000 (Mon, 18 Jan 2010) | 9 lines
Merged revisions 77595 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77595 | ezio.melotti | 2010-01-18 11:10:26 +0200 (Mon, 18 Jan 2010) | 1 line
#7730: remove spaces after functions names
........
................
r77602 | antoine.pitrou | 2010-01-18 21:20:53 +0000 (Mon, 18 Jan 2010) | 17 lines
Merged revisions 77599-77601 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77599 | antoine.pitrou | 2010-01-18 22:04:00 +0100 (lun., 18 janv. 2010) | 3 lines
Add iobench to the Tools directory (see December python-dev discussion)
........
r77600 | antoine.pitrou | 2010-01-18 22:10:31 +0100 (lun., 18 janv. 2010) | 3 lines
Add ccbench to the Tools directory
........
r77601 | antoine.pitrou | 2010-01-18 22:15:21 +0100 (lun., 18 janv. 2010) | 3 lines
Add a NEWS entry for r77599 and r77600.
........
................
r77604 | benjamin.peterson | 2010-01-19 00:09:57 +0000 (Tue, 19 Jan 2010) | 4 lines
use assert[Not]In where appropriate
A patch from Dave Malcolm.
................
Added:
python/branches/py3k-cdecimal/Lib/email/test/data/msg_45.txt
- copied unchanged from r77604, /python/branches/py3k/Lib/email/test/data/msg_45.txt
python/branches/py3k-cdecimal/Lib/test/test_strtod.py
- copied unchanged from r77604, /python/branches/py3k/Lib/test/test_strtod.py
python/branches/py3k-cdecimal/Objects/stringlib/split.h
- copied unchanged from r77604, /python/branches/py3k/Objects/stringlib/split.h
python/branches/py3k-cdecimal/Tools/ccbench/
- copied from r77604, /python/branches/py3k/Tools/ccbench/
python/branches/py3k-cdecimal/Tools/iobench/
- copied from r77604, /python/branches/py3k/Tools/iobench/
Modified:
python/branches/py3k-cdecimal/ (props changed)
python/branches/py3k-cdecimal/Doc/c-api/init.rst
python/branches/py3k-cdecimal/Doc/library/2to3.rst
python/branches/py3k-cdecimal/Doc/library/email.generator.rst
python/branches/py3k-cdecimal/Doc/library/email.message.rst
python/branches/py3k-cdecimal/Doc/library/email.mime.rst
python/branches/py3k-cdecimal/Doc/library/gzip.rst
python/branches/py3k-cdecimal/Doc/library/importlib.rst
python/branches/py3k-cdecimal/Doc/library/inspect.rst
python/branches/py3k-cdecimal/Doc/library/math.rst
python/branches/py3k-cdecimal/Doc/library/os.rst
python/branches/py3k-cdecimal/Doc/library/re.rst
python/branches/py3k-cdecimal/Doc/library/stdtypes.rst
python/branches/py3k-cdecimal/Doc/library/unittest.rst
python/branches/py3k-cdecimal/Doc/library/weakref.rst
python/branches/py3k-cdecimal/Doc/library/zipimport.rst
python/branches/py3k-cdecimal/Doc/using/windows.rst
python/branches/py3k-cdecimal/Doc/whatsnew/2.7.rst
python/branches/py3k-cdecimal/Include/bytearrayobject.h
python/branches/py3k-cdecimal/Lib/_weakrefset.py
python/branches/py3k-cdecimal/Lib/cmd.py
python/branches/py3k-cdecimal/Lib/distutils/ccompiler.py
python/branches/py3k-cdecimal/Lib/distutils/tests/test_unixccompiler.py
python/branches/py3k-cdecimal/Lib/distutils/unixccompiler.py
python/branches/py3k-cdecimal/Lib/email/generator.py
python/branches/py3k-cdecimal/Lib/email/test/test_email.py
python/branches/py3k-cdecimal/Lib/email/utils.py
python/branches/py3k-cdecimal/Lib/gzip.py
python/branches/py3k-cdecimal/Lib/idlelib/NEWS.txt
python/branches/py3k-cdecimal/Lib/logging/__init__.py
python/branches/py3k-cdecimal/Lib/pickle.py
python/branches/py3k-cdecimal/Lib/platform.py
python/branches/py3k-cdecimal/Lib/ssl.py
python/branches/py3k-cdecimal/Lib/test/crashers/bogus_code_obj.py
python/branches/py3k-cdecimal/Lib/test/floating_points.txt
python/branches/py3k-cdecimal/Lib/test/https_svn_python_org_root.pem
python/branches/py3k-cdecimal/Lib/test/pickletester.py
python/branches/py3k-cdecimal/Lib/test/regrtest.py
python/branches/py3k-cdecimal/Lib/test/test_bigmem.py
python/branches/py3k-cdecimal/Lib/test/test_binascii.py
python/branches/py3k-cdecimal/Lib/test/test_builtin.py
python/branches/py3k-cdecimal/Lib/test/test_bytes.py
python/branches/py3k-cdecimal/Lib/test/test_cgi.py
python/branches/py3k-cdecimal/Lib/test/test_cmd.py
python/branches/py3k-cdecimal/Lib/test/test_cmd_line.py
python/branches/py3k-cdecimal/Lib/test/test_cmd_line_script.py
python/branches/py3k-cdecimal/Lib/test/test_collections.py
python/branches/py3k-cdecimal/Lib/test/test_compile.py
python/branches/py3k-cdecimal/Lib/test/test_contains.py
python/branches/py3k-cdecimal/Lib/test/test_copyreg.py
python/branches/py3k-cdecimal/Lib/test/test_csv.py
python/branches/py3k-cdecimal/Lib/test/test_datetime.py
python/branches/py3k-cdecimal/Lib/test/test_dbm.py
python/branches/py3k-cdecimal/Lib/test/test_dbm_dumb.py
python/branches/py3k-cdecimal/Lib/test/test_dbm_gnu.py
python/branches/py3k-cdecimal/Lib/test/test_dbm_ndbm.py
python/branches/py3k-cdecimal/Lib/test/test_decimal.py
python/branches/py3k-cdecimal/Lib/test/test_defaultdict.py
python/branches/py3k-cdecimal/Lib/test/test_deque.py
python/branches/py3k-cdecimal/Lib/test/test_descr.py
python/branches/py3k-cdecimal/Lib/test/test_dict.py
python/branches/py3k-cdecimal/Lib/test/test_dictviews.py
python/branches/py3k-cdecimal/Lib/test/test_exceptions.py
python/branches/py3k-cdecimal/Lib/test/test_float.py
python/branches/py3k-cdecimal/Lib/test/test_funcattrs.py
python/branches/py3k-cdecimal/Lib/test/test_glob.py
python/branches/py3k-cdecimal/Lib/test/test_gzip.py
python/branches/py3k-cdecimal/Lib/test/test_hashlib.py
python/branches/py3k-cdecimal/Lib/test/test_http_cookiejar.py
python/branches/py3k-cdecimal/Lib/test/test_import.py
python/branches/py3k-cdecimal/Lib/test/test_index.py
python/branches/py3k-cdecimal/Lib/test/test_inspect.py
python/branches/py3k-cdecimal/Lib/test/test_ioctl.py
python/branches/py3k-cdecimal/Lib/test/test_iter.py
python/branches/py3k-cdecimal/Lib/test/test_logging.py
python/branches/py3k-cdecimal/Lib/test/test_long.py
python/branches/py3k-cdecimal/Lib/test/test_mmap.py
python/branches/py3k-cdecimal/Lib/test/test_multiprocessing.py
python/branches/py3k-cdecimal/Lib/test/test_os.py
python/branches/py3k-cdecimal/Lib/test/test_peepholer.py
python/branches/py3k-cdecimal/Lib/test/test_pep352.py
python/branches/py3k-cdecimal/Lib/test/test_poplib.py
python/branches/py3k-cdecimal/Lib/test/test_posix.py
python/branches/py3k-cdecimal/Lib/test/test_posixpath.py
python/branches/py3k-cdecimal/Lib/test/test_pwd.py
python/branches/py3k-cdecimal/Lib/test/test_pyclbr.py
python/branches/py3k-cdecimal/Lib/test/test_pydoc.py
python/branches/py3k-cdecimal/Lib/test/test_raise.py
python/branches/py3k-cdecimal/Lib/test/test_random.py
python/branches/py3k-cdecimal/Lib/test/test_range.py
python/branches/py3k-cdecimal/Lib/test/test_re.py
python/branches/py3k-cdecimal/Lib/test/test_reprlib.py
python/branches/py3k-cdecimal/Lib/test/test_runpy.py
python/branches/py3k-cdecimal/Lib/test/test_sax.py
python/branches/py3k-cdecimal/Lib/test/test_scope.py
python/branches/py3k-cdecimal/Lib/test/test_set.py
python/branches/py3k-cdecimal/Lib/test/test_site.py
python/branches/py3k-cdecimal/Lib/test/test_socket.py
python/branches/py3k-cdecimal/Lib/test/test_structseq.py
python/branches/py3k-cdecimal/Lib/test/test_subprocess.py
python/branches/py3k-cdecimal/Lib/test/test_sys.py
python/branches/py3k-cdecimal/Lib/test/test_tarfile.py
python/branches/py3k-cdecimal/Lib/test/test_telnetlib.py
python/branches/py3k-cdecimal/Lib/test/test_tempfile.py
python/branches/py3k-cdecimal/Lib/test/test_threading.py
python/branches/py3k-cdecimal/Lib/test/test_threading_local.py
python/branches/py3k-cdecimal/Lib/test/test_traceback.py
python/branches/py3k-cdecimal/Lib/test/test_types.py
python/branches/py3k-cdecimal/Lib/test/test_unicode.py
python/branches/py3k-cdecimal/Lib/test/test_unicode_file.py
python/branches/py3k-cdecimal/Lib/test/test_unicodedata.py
python/branches/py3k-cdecimal/Lib/test/test_unittest.py
python/branches/py3k-cdecimal/Lib/test/test_urllib.py
python/branches/py3k-cdecimal/Lib/test/test_urllib2.py
python/branches/py3k-cdecimal/Lib/test/test_userdict.py
python/branches/py3k-cdecimal/Lib/test/test_warnings.py
python/branches/py3k-cdecimal/Lib/test/test_wave.py
python/branches/py3k-cdecimal/Lib/test/test_weakref.py
python/branches/py3k-cdecimal/Lib/test/test_weakset.py
python/branches/py3k-cdecimal/Lib/test/test_wsgiref.py
python/branches/py3k-cdecimal/Lib/test/test_zipfile.py
python/branches/py3k-cdecimal/Lib/test/test_zipimport.py
python/branches/py3k-cdecimal/Lib/test/test_zipimport_support.py
python/branches/py3k-cdecimal/Lib/turtle.py
python/branches/py3k-cdecimal/Lib/unittest/__init__.py
python/branches/py3k-cdecimal/Lib/wave.py
python/branches/py3k-cdecimal/Lib/weakref.py
python/branches/py3k-cdecimal/Mac/Resources/app/Info.plist.in
python/branches/py3k-cdecimal/Makefile.pre.in
python/branches/py3k-cdecimal/Misc/ACKS
python/branches/py3k-cdecimal/Misc/NEWS
python/branches/py3k-cdecimal/Misc/RPM/python-3.2.spec
python/branches/py3k-cdecimal/Misc/build.sh
python/branches/py3k-cdecimal/Misc/developers.txt
python/branches/py3k-cdecimal/Misc/gdbinit
python/branches/py3k-cdecimal/Modules/_ctypes/libffi/fficonfig.py.in
python/branches/py3k-cdecimal/Modules/_hashopenssl.c
python/branches/py3k-cdecimal/Modules/_pickle.c
python/branches/py3k-cdecimal/Modules/_sre.c
python/branches/py3k-cdecimal/Modules/_testcapimodule.c
python/branches/py3k-cdecimal/Modules/binascii.c
python/branches/py3k-cdecimal/Modules/posixmodule.c
python/branches/py3k-cdecimal/Objects/bytearrayobject.c
python/branches/py3k-cdecimal/Objects/bytesobject.c
python/branches/py3k-cdecimal/Objects/longobject.c
python/branches/py3k-cdecimal/Objects/stringlib/count.h
python/branches/py3k-cdecimal/Objects/stringlib/ctype.h
python/branches/py3k-cdecimal/Objects/stringlib/fastsearch.h
python/branches/py3k-cdecimal/Objects/stringlib/find.h
python/branches/py3k-cdecimal/Objects/stringlib/partition.h
python/branches/py3k-cdecimal/Objects/stringlib/stringdefs.h
python/branches/py3k-cdecimal/Objects/stringlib/transmogrify.h
python/branches/py3k-cdecimal/Objects/stringlib/unicodedefs.h
python/branches/py3k-cdecimal/Objects/unicodeobject.c
python/branches/py3k-cdecimal/PC/VS8.0/pythoncore.vcproj
python/branches/py3k-cdecimal/PCbuild/pythoncore.vcproj
python/branches/py3k-cdecimal/Python/dtoa.c
python/branches/py3k-cdecimal/Python/peephole.c
python/branches/py3k-cdecimal/setup.py
Modified: python/branches/py3k-cdecimal/Doc/c-api/init.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/c-api/init.rst (original)
+++ python/branches/py3k-cdecimal/Doc/c-api/init.rst Thu Jan 21 20:32:23 2010
@@ -256,14 +256,15 @@
triple: module; search; path
single: path (in module sys)
- Return the default module search path; this is computed from the program name
- (set by :cfunc:`Py_SetProgramName` above) and some environment variables. The
- returned string consists of a series of directory names separated by a platform
- dependent delimiter character. The delimiter character is ``':'`` on Unix and
- Mac OS X, ``';'`` on Windows. The returned string points into static storage;
- the caller should not modify its value. The value is available to Python code
- as the list ``sys.path``, which may be modified to change the future search path
- for loaded modules.
+ Return the default module search path; this is computed from the program name
+ (set by :cfunc:`Py_SetProgramName` above) and some environment variables.
+ The returned string consists of a series of directory names separated by a
+ platform dependent delimiter character. The delimiter character is ``':'``
+ on Unix and Mac OS X, ``';'`` on Windows. The returned string points into
+ static storage; the caller should not modify its value. The list
+ :data:`sys.path` is initialized with this value on interpreter startup; it
+ can be (and usually is) modified later to change the search path for loading
+ modules.
.. XXX should give the exact rules
Modified: python/branches/py3k-cdecimal/Doc/library/2to3.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/2to3.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/2to3.rst Thu Jan 21 20:32:23 2010
@@ -129,9 +129,11 @@
Fixes dictionary iteration methods. :meth:`dict.iteritems` is converted to
:meth:`dict.items`, :meth:`dict.iterkeys` to :meth:`dict.keys`, and
- :meth:`dict.itervalues` to :meth:`dict.values`. It also wraps existing
- usages of :meth:`dict.items`, :meth:`dict.keys`, and :meth:`dict.values` in a
- call to :class:`list`.
+ :meth:`dict.itervalues` to :meth:`dict.values`. Similarly,
+ :meth:`dict.viewitems`, :meth:`dict.viewkeys` and :meth:`dict.viewvalues`
+ are converted respectively to :meth:`dict.items`, :meth:`dict.keys` and
+ :meth:`dict.values`. It also wraps existing usages of :meth:`dict.items`,
+ :meth:`dict.keys`, and :meth:`dict.values` in a call to :class:`list`.
.. 2to3fixer:: except
Modified: python/branches/py3k-cdecimal/Doc/library/email.generator.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/email.generator.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/email.generator.rst Thu Jan 21 20:32:23 2010
@@ -17,7 +17,10 @@
standards-compliant way, should handle MIME and non-MIME email messages just
fine, and is designed so that the transformation from flat text, to a message
structure via the :class:`~email.parser.Parser` class, and back to flat text,
-is idempotent (the input is identical to the output).
+is idempotent (the input is identical to the output). On the other hand, using
+the Generator on a :class:`~email.message.Message` constructed by program may
+result in changes to the :class:`~email.message.Message` object as defaults are
+filled in.
Here are the public methods of the :class:`Generator` class, imported from the
:mod:`email.generator` module:
Modified: python/branches/py3k-cdecimal/Doc/library/email.message.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/email.message.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/email.message.rst Thu Jan 21 20:32:23 2010
@@ -40,7 +40,10 @@
Return the entire message flattened as a string. When optional *unixfrom*
is ``True``, the envelope header is included in the returned string.
- *unixfrom* defaults to ``False``.
+ *unixfrom* defaults to ``False``. Flattening the message may trigger
+ changes to the :class:`Message` if defaults need to be filled in to
+ complete the transformation to a string (for example, MIME boundaries may
+ be generated or modified).
Note that this method is provided as a convenience and may not always
format the message the way you want. For example, by default it mangles
Modified: python/branches/py3k-cdecimal/Doc/library/email.mime.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/email.mime.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/email.mime.rst Thu Jan 21 20:32:23 2010
@@ -69,7 +69,8 @@
also be added.
Optional *boundary* is the multipart boundary string. When ``None`` (the
- default), the boundary is calculated when needed.
+ default), the boundary is calculated when needed (for example, when the
+ message is serialized).
*_subparts* is a sequence of initial subparts for the payload. It must be
possible to convert this sequence to a list. You can always attach new subparts
Modified: python/branches/py3k-cdecimal/Doc/library/gzip.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/gzip.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/gzip.rst Thu Jan 21 20:32:23 2010
@@ -72,6 +72,9 @@
.. versionchanged:: 3.1
Support for the :keyword:`with` statement was added.
+ .. versionchanged:: 3.2
+ Support for zero-padded files was added.
+
.. function:: open(filename, mode='rb', compresslevel=9)
Modified: python/branches/py3k-cdecimal/Doc/library/importlib.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/importlib.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/importlib.rst Thu Jan 21 20:32:23 2010
@@ -54,7 +54,7 @@
:pep:`366`
Main module explicit relative imports
- :pep:`3128`
+ :pep:`3120`
Using UTF-8 as the Default Source Encoding
Modified: python/branches/py3k-cdecimal/Doc/library/inspect.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/inspect.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/inspect.rst Thu Jan 21 20:32:23 2010
@@ -387,7 +387,7 @@
.. function:: getargspec(func)
- Get the names and default values of a function's arguments. A
+ Get the names and default values of a Python function's arguments. A
:term:`named tuple` ``ArgSpec(args, varargs, keywords,
defaults)`` is returned. *args* is a list of
the argument names. *varargs* and *varkw* are the names of the ``*`` and
@@ -402,8 +402,8 @@
.. function:: getfullargspec(func)
- Get the names and default values of a function's arguments. A :term:`named
- tuple` is returned:
+ Get the names and default values of a Python function's arguments. A
+ :term:`named tuple` is returned:
``FullArgSpec(args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults,
annotations)``
Modified: python/branches/py3k-cdecimal/Doc/library/math.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/math.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/math.rst Thu Jan 21 20:32:23 2010
@@ -347,10 +347,7 @@
error-reporting behavior from the platform C implementation. As a result,
the specific exceptions raised in error cases (and even whether some
arguments are considered to be exceptional at all) are not defined in any
- useful cross-platform or cross-release way. For example, whether
- ``math.log(0)`` returns ``-Inf`` or raises :exc:`ValueError` or
- :exc:`OverflowError` isn't defined, and in cases where ``math.log(0)`` raises
- :exc:`OverflowError`, ``math.log(0L)`` may raise :exc:`ValueError` instead.
+ useful cross-platform or cross-release way.
All functions return a quiet *NaN* if at least one of the args is *NaN*.
Signaling *NaN*\s raise an exception. The exception type still depends on the
Modified: python/branches/py3k-cdecimal/Doc/library/os.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/os.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/os.rst Thu Jan 21 20:32:23 2010
@@ -1065,9 +1065,9 @@
>>> import os
>>> statinfo = os.stat('somefile.txt')
>>> statinfo
- (33188, 422511L, 769L, 1, 1032, 100, 926L, 1105022698,1105022732, 1105022732)
+ (33188, 422511, 769, 1, 1032, 100, 926, 1105022698,1105022732, 1105022732)
>>> statinfo.st_size
- 926L
+ 926
>>>
Modified: python/branches/py3k-cdecimal/Doc/library/re.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/re.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/re.rst Thu Jan 21 20:32:23 2010
@@ -849,16 +849,16 @@
A moderately complicated example:
- >>> m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Malcom Reynolds")
+ >>> m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Malcolm Reynolds")
>>> m.group('first_name')
- 'Malcom'
+ 'Malcolm'
>>> m.group('last_name')
'Reynolds'
Named groups can also be referred to by their index:
>>> m.group(1)
- 'Malcom'
+ 'Malcolm'
>>> m.group(2)
'Reynolds'
@@ -898,9 +898,9 @@
the subgroup name. The *default* argument is used for groups that did not
participate in the match; it defaults to ``None``. For example:
- >>> m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Malcom Reynolds")
+ >>> m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Malcolm Reynolds")
>>> m.groupdict()
- {'first_name': 'Malcom', 'last_name': 'Reynolds'}
+ {'first_name': 'Malcolm', 'last_name': 'Reynolds'}
.. method:: MatchObject.start(group=0)
Modified: python/branches/py3k-cdecimal/Doc/library/stdtypes.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/stdtypes.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/stdtypes.rst Thu Jan 21 20:32:23 2010
@@ -457,6 +457,69 @@
.. versionadded:: 3.1
+ .. method:: int.to_bytes(length, byteorder, \*, signed=False)
+
+ Return an array of bytes representing an integer.
+
+ >>> (1024).to_bytes(2, byteorder='big')
+ b'\x04\x00'
+ >>> (1024).to_bytes(10, byteorder='big')
+ b'\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00'
+ >>> (-1024).to_bytes(10, byteorder='big', signed=True)
+ b'\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00'
+ >>> x = 1000
+ >>> x.to_bytes((x.bit_length() // 8) + 1, byteorder='little')
+ b'\xe8\x03'
+
+ The integer is represented using *length* bytes. An :exc:`OverflowError`
+ is raised if the integer is not representable with the given number of
+ bytes.
+
+ The *byteorder* argument determines the byte order used to represent the
+ integer. If *byteorder* is ``"big"``, the most significant byte is at the
+ beginning of the byte array. If *byteorder* is ``"little"``, the most
+ significant byte is at the end of the byte array. To request the native
+ byte order of the host system, use :data:`sys.byteorder` as the byte order
+ value.
+
+ The *signed* argument determines whether two's complement is used to
+ represent the integer. If *signed* is ``False`` and a negative integer is
+ given, an :exc:`OverflowError` is raised. The default value for *signed*
+ is ``False``.
+
+ .. versionadded:: 3.2
+
+ .. classmethod:: int.from_bytes(bytes, byteorder, \*, signed=False)
+
+ Return the integer represented by the given array of bytes.
+
+ >>> int.from_bytes(b'\x00\x10', byteorder='big')
+ 16
+ >>> int.from_bytes(b'\x00\x10', byteorder='little')
+ 4096
+ >>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=True)
+ -1024
+ >>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=False)
+ 64512
+ >>> int.from_bytes([255, 0, 0], byteorder='big')
+ 16711680
+
+ The argument *bytes* must either support the buffer protocol or be an
+ iterable producing bytes. :class:`bytes` and :class:`bytearray` are
+ examples of built-in objects that support the buffer protocol.
+
+ The *byteorder* argument determines the byte order used to represent the
+ integer. If *byteorder* is ``"big"``, the most significant byte is at the
+ beginning of the byte array. If *byteorder* is ``"little"``, the most
+ significant byte is at the end of the byte array. To request the native
+ byte order of the host system, use :data:`sys.byteorder` as the byte order
+ value.
+
+ The *signed* argument indicates whether two's complement is used to
+ represent the integer.
+
+ .. versionadded:: 3.2
+
Additional Methods on Float
---------------------------
Modified: python/branches/py3k-cdecimal/Doc/library/unittest.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/unittest.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/unittest.rst Thu Jan 21 20:32:23 2010
@@ -780,7 +780,7 @@
.. versionadded:: 3.1
- .. method:: assertRegexpMatches(text, regexp, msg=None):
+ .. 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
Modified: python/branches/py3k-cdecimal/Doc/library/weakref.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/weakref.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/weakref.rst Thu Jan 21 20:32:23 2010
@@ -159,7 +159,7 @@
.. method:: WeakKeyDictionary.keyrefs()
- Return an :term:`iterator` that yields the weak references to the keys.
+ Return an iterable of the weak references to the keys.
.. class:: WeakValueDictionary([dict])
@@ -182,7 +182,7 @@
.. method:: WeakValueDictionary.valuerefs()
- Return an :term:`iterator` that yields the weak references to the values.
+ Return an iterable of the weak references to the values.
.. class:: WeakSet([elements])
Modified: python/branches/py3k-cdecimal/Doc/library/zipimport.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/zipimport.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/zipimport.rst Thu Jan 21 20:32:23 2010
@@ -26,6 +26,8 @@
corresponding :file:`.pyc` or :file:`.pyo` file, meaning that if a ZIP archive
doesn't contain :file:`.pyc` files, importing may be rather slow.
+ZIP archives with an archive comment are currently not supported.
+
.. seealso::
`PKZIP Application Note <http://www.pkware.com/documents/casestudies/APPNOTE.TXT>`_
Modified: python/branches/py3k-cdecimal/Doc/using/windows.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/using/windows.rst (original)
+++ python/branches/py3k-cdecimal/Doc/using/windows.rst Thu Jan 21 20:32:23 2010
@@ -166,12 +166,13 @@
.. ``
-Modifying the module search path can also be done through the Windows registry:
-Edit
-:file:`HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\{version}\\PythonPath\\`,
-as described above for the environment variable :envvar:`%PYTHONPATH%`. A
-convenient registry editor is :program:`regedit` (start it by typing "regedit"
-into :menuselection:`Start --> Run`).
+Modifying the module search path can also be done through the Windows registry
+under the key :file:`HKLM\\SOFTWARE\\Python\\PythonCore\\{version}\\PythonPath`.
+Subkeys which have semicolon-delimited path strings as their default value will
+cause each path to be searched. Multiple subkeys can be created and are
+appended to the path in alphabetical order. A convenient registry editor is
+:program:`regedit` (start it by typing "regedit" into :menuselection:`Start -->
+Run`).
Executing scripts
Modified: python/branches/py3k-cdecimal/Doc/whatsnew/2.7.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/whatsnew/2.7.rst (original)
+++ python/branches/py3k-cdecimal/Doc/whatsnew/2.7.rst Thu Jan 21 20:32:23 2010
@@ -264,10 +264,12 @@
Windows, and on Unix platforms using the gcc, icc, or suncc
compilers. There may be a small number of platforms where correct
operation of this code cannot be guaranteed, so the code is not
- used on such systems.
+ used on such systems. You can find out which code is being used
+ by checking :data:`sys.float_repr_style`, which will be ``short``
+ if the new code is in use and ``legacy`` if it isn't.
- Implemented by Mark Dickinson, using David Gay's :file:`dtoa.c` library;
- :issue:`7117`.
+ Implemented by Eric Smith and Mark Dickinson, using David Gay's
+ :file:`dtoa.c` library; :issue:`7117`.
* The :meth:`str.format` method now supports automatic numbering of the replacement
fields. This makes using :meth:`str.format` more closely resemble using
@@ -358,6 +360,11 @@
on the :exc:`IOError` exception when trying to open a directory
on POSIX platforms. (Noted by Jan Kaliszewski; :issue:`4764`.)
+* The Python tokenizer now translates line endings itself, so the
+ :func:`compile` built-in function can now accept code using any
+ line-ending convention. Additionally, it no longer requires that the
+ code end in a newline.
+
* Extra parentheses in function definitions are illegal in Python 3.x,
meaning that you get a syntax error from ``def f((x)): pass``. In
Python3-warning mode, Python 2.7 will now warn about this odd usage.
@@ -433,6 +440,8 @@
Various benchmarks show speedups of between 50% and 150% for long
integer divisions and modulo operations.
(Contributed by Mark Dickinson; :issue:`5512`.)
+ Bitwise operations are also significantly faster (initial patch by
+ Gregory Smith; :issue:`1087418`).
* The implementation of ``%`` checks for the left-side operand being
a Python string and special-cases it; this results in a 1-3%
@@ -444,6 +453,16 @@
faster bytecode. (Patch by Antoine Pitrou, back-ported to 2.7
by Jeffrey Yasskin; :issue:`4715`.)
+* Converting an integer or long integer to a decimal string was made
+ faster by special-casing base 10 instead of using a generalized
+ conversion function that supports arbitrary bases.
+ (Patch by Gawain Bolton; :issue:`6713`.)
+
+* The :meth:`rindex`, :meth:`rpartition`, and :meth:`rsplit` methods
+ of string objects now uses a fast reverse-search algorithm instead of
+ a character-by-character scan. This is often faster by a factor of 10.
+ (Added by Florent Xicluna; :issue:`7462`.)
+
* The :mod:`pickle` and :mod:`cPickle` modules now automatically
intern the strings used for attribute names, reducing memory usage
of the objects resulting from unpickling. (Contributed by Jake
@@ -453,11 +472,6 @@
nearly halving the time required to pickle them.
(Contributed by Collin Winter; :issue:`5670`.)
-* Converting an integer or long integer to a decimal string was made
- faster by special-casing base 10 instead of using a generalized
- conversion function that supports arbitrary bases.
- (Patch by Gawain Bolton; :issue:`6713`.)
-
.. ======================================================================
New and Improved Modules
@@ -602,6 +616,10 @@
XXX link to file:///MacDev/svn.python.org/python-trunk/Doc/build/html/distutils/examples.html#reading-the-metadata
(Contributed by Tarek Ziade; :issue:`7457`.)
+ :file:`setup.py` files will now accept a :option:`--no-user-cfg` switch
+ to skip reading the :file:`~/.pydistutils.cfg` file. (Suggested by
+ by Michael Hoffman, and implemented by Paul Winkler; :issue:`1180`.)
+
* The :class:`Fraction` class now accepts two rational numbers
as arguments to its constructor.
(Implemented by Mark Dickinson; :issue:`5812`.)
@@ -625,14 +643,6 @@
recorded in a gzipped file by providing an optional timestamp to
the constructor. (Contributed by Jacques Frechet; :issue:`4272`.)
-* The :mod:`hashlib` module was inconsistent about accepting
- input as a Unicode object or an object that doesn't support
- the buffer protocol. The behavior was different depending on
- whether :mod:`hashlib` was using an external OpenSSL library
- or its built-in implementations. Python 2.7 makes the
- behavior consistent, always rejecting such objects by raising a
- :exc:`TypeError`. (Fixed by Gregory P. Smith; :issue:`3745`.)
-
* The default :class:`HTTPResponse` class used by the :mod:`httplib` module now
supports buffering, resulting in much faster reading of HTTP responses.
(Contributed by Kristjan Valur Jonsson; :issue:`4879`.)
@@ -745,6 +755,10 @@
to store data.
(Contributed by Tarek Ziade; :issue:`6693`.)
+* The :mod:`socket` module's :class:`SSL` objects now support the
+ buffer API, which fixed a test suite failure. (Fixed by Antoine Pitrou;
+ :issue:`7133`.)
+
* The :mod:`SocketServer` module's :class:`TCPServer` class now
has a :attr:`disable_nagle_algorithm` class attribute.
The default value is False; if overridden to be True,
@@ -858,6 +872,10 @@
whether the two values evaluate to the same object or not.
(Added by Michael Foord; :issue:`2578`.)
+* :meth:`assertIsInstance` and :meth:`assertNotIsInstance` check whether
+ the resulting object is an instance of a particular class, or of
+ one of a tuple of classes. (Added by Georg Brandl; :issue:`7031`.)
+
* :meth:`assertGreater`, :meth:`assertGreaterEqual`,
:meth:`assertLess`, and :meth:`assertLessEqual` compare
two quantities.
@@ -1025,6 +1043,11 @@
a :ctype:`long`, an *overflow* flag is set and returned to the caller.
(Contributed by Case Van Horsen; :issue:`7528`.)
+* New function: stemming from the rewrite of string-to-float conversion,
+ a new :cfunc:`PyOS_string_to_double` function was added. The old
+ :cfunc:`PyOS_ascii_strtod` and :cfunc:`PyOS_ascii_atof` functions
+ are now deprecated.
+
* New macros: the Python header files now define the following macros:
:cmacro:`Py_ISALNUM`,
:cmacro:`Py_ISALPHA`,
@@ -1067,10 +1090,30 @@
(Fixed by Thomas Wouters; :issue:`1590864`.)
+* The :cfunc:`Py_Finalize` function now calls the internal
+ :func:`threading._shutdown` function; this prevents some exceptions from
+ being raised when an interpreter shuts down.
+ (Patch by Adam Olsen; :issue:`1722344`.)
+
* Global symbols defined by the :mod:`ctypes` module are now prefixed
with ``Py``, or with ``_ctypes``. (Implemented by Thomas
Heller; :issue:`3102`.)
+* New configure option: the :option:`--with-system-expat` switch allows
+ building the :mod:`pyexpat` module to use the system Expat library.
+ (Contributed by Arfrever Frehtes Taifersar Arahesis; :issue:`7609`.)
+
+* New configure option: Compiling Python with the
+ :option:`--with-valgrind` option will now disable the pymalloc
+ allocator, which is difficult for the Valgrind to analyze correctly.
+ Valgrind will therefore be better at detecting memory leaks and
+ overruns. (Contributed by James Henstridge; :issue:`2422`.)
+
+* New configure option: you can now supply no arguments to
+ :option:`--with-dbmliborder=` in order to build none of the various
+ DBM modules. (Added by Arfrever Frehtes Taifersar Arahesis;
+ :issue:`6491`.)
+
* The :program:`configure` script now checks for floating-point rounding bugs
on certain 32-bit Intel chips and defines a :cmacro:`X87_DOUBLE_ROUNDING`
preprocessor definition. No code currently uses this definition,
@@ -1083,11 +1126,6 @@
* The build process now supports Subversion 1.7. (Contributed by
Arfrever Frehtes Taifersar Arahesis; :issue:`6094`.)
-* Compiling Python with the :option:`--with-valgrind` option will now
- disable the pymalloc allocator, which is difficult for the Valgrind to
- analyze correctly. Valgrind will therefore be better at detecting
- memory leaks and overruns. (Contributed by James Henstridge; :issue:`2422`.)
-
.. ======================================================================
@@ -1139,12 +1177,14 @@
The :option:`-r` option also reports the seed that was used
(Added by Collin Winter.)
-* The :file:`regrtest.py` script now takes a :option:`-j` switch
- that takes an integer specifying how many tests run in parallel. This
+* Another :file:`regrtest.py` switch is :option:`-j`, which
+ takes an integer specifying how many tests run in parallel. This
allows reducing the total runtime on multi-core machines.
This option is compatible with several other options, including the
:option:`-R` switch which is known to produce long runtimes.
- (Added by Antoine Pitrou, :issue:`6152`.)
+ (Added by Antoine Pitrou, :issue:`6152`.) This can also be used
+ with a new :option:`-F` switch that runs selected tests in a loop
+ until they fail. (Added by Antoine Pitrou; :issue:`7312`.)
.. ======================================================================
@@ -1175,6 +1215,17 @@
nothing when a negative length is requested, as other file-like
objects do. (:issue:`7348`).
+For C extensions:
+
+* C extensions that use integer format codes with the ``PyArg_Parse*``
+ family of functions will now raise a :exc:`TypeError` exception
+ instead of triggering a :exc:`DeprecationWarning` (:issue:`5080`).
+
+* Use the new :cfunc:`PyOS_string_to_double` function instead of the old
+ :cfunc:`PyOS_ascii_strtod` and :cfunc:`PyOS_ascii_atof` functions,
+ which are now deprecated.
+
+
.. ======================================================================
Modified: python/branches/py3k-cdecimal/Include/bytearrayobject.h
==============================================================================
--- python/branches/py3k-cdecimal/Include/bytearrayobject.h (original)
+++ python/branches/py3k-cdecimal/Include/bytearrayobject.h Thu Jan 21 20:32:23 2010
@@ -44,9 +44,13 @@
PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t);
/* Macros, trading safety for speed */
-#define PyByteArray_AS_STRING(self) (assert(PyByteArray_Check(self)),((PyByteArrayObject *)(self))->ob_bytes)
+#define PyByteArray_AS_STRING(self) \
+ (assert(PyByteArray_Check(self)), \
+ Py_SIZE(self) ? ((PyByteArrayObject *)(self))->ob_bytes : _PyByteArray_empty_string)
#define PyByteArray_GET_SIZE(self) (assert(PyByteArray_Check(self)),Py_SIZE(self))
+PyAPI_DATA(char) _PyByteArray_empty_string[];
+
#ifdef __cplusplus
}
#endif
Modified: python/branches/py3k-cdecimal/Lib/_weakrefset.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/_weakrefset.py (original)
+++ python/branches/py3k-cdecimal/Lib/_weakrefset.py Thu Jan 21 20:32:23 2010
@@ -6,22 +6,61 @@
__all__ = ['WeakSet']
+
+class _IterationGuard:
+ # This context manager registers itself in the current iterators of the
+ # weak container, such as to delay all removals until the context manager
+ # exits.
+ # This technique should be relatively thread-safe (since sets are).
+
+ def __init__(self, weakcontainer):
+ # Don't create cycles
+ self.weakcontainer = ref(weakcontainer)
+
+ def __enter__(self):
+ w = self.weakcontainer()
+ if w is not None:
+ w._iterating.add(self)
+ return self
+
+ def __exit__(self, e, t, b):
+ w = self.weakcontainer()
+ if w is not None:
+ s = w._iterating
+ s.remove(self)
+ if not s:
+ w._commit_removals()
+
+
class WeakSet:
def __init__(self, data=None):
self.data = set()
def _remove(item, selfref=ref(self)):
self = selfref()
if self is not None:
- self.data.discard(item)
+ if self._iterating:
+ self._pending_removals.append(item)
+ else:
+ self.data.discard(item)
self._remove = _remove
+ # A list of keys to be removed
+ self._pending_removals = []
+ self._iterating = set()
if data is not None:
self.update(data)
+ def _commit_removals(self):
+ l = self._pending_removals
+ discard = self.data.discard
+ while l:
+ discard(l.pop())
+
def __iter__(self):
- for itemref in self.data:
- item = itemref()
- if item is not None:
- yield item
+ with _IterationGuard(self):
+ for itemref in self.data:
+ item = itemref()
+ if item is not None:
+ yield item
def __len__(self):
return sum(x() is not None for x in self.data)
@@ -34,15 +73,21 @@
getattr(self, '__dict__', None))
def add(self, item):
+ if self._pending_removals:
+ self._commit_removals()
self.data.add(ref(item, self._remove))
def clear(self):
+ if self._pending_removals:
+ self._commit_removals()
self.data.clear()
def copy(self):
return self.__class__(self)
def pop(self):
+ if self._pending_removals:
+ self._commit_removals()
while True:
try:
itemref = self.data.pop()
@@ -53,17 +98,24 @@
return item
def remove(self, item):
+ if self._pending_removals:
+ self._commit_removals()
self.data.remove(ref(item))
def discard(self, item):
+ if self._pending_removals:
+ self._commit_removals()
self.data.discard(ref(item))
def update(self, other):
+ if self._pending_removals:
+ self._commit_removals()
if isinstance(other, self.__class__):
self.data.update(other.data)
else:
for element in other:
self.add(element)
+
def __ior__(self, other):
self.update(other)
return self
@@ -82,11 +134,15 @@
__sub__ = difference
def difference_update(self, other):
+ if self._pending_removals:
+ self._commit_removals()
if self is other:
self.data.clear()
else:
self.data.difference_update(ref(item) for item in other)
def __isub__(self, other):
+ if self._pending_removals:
+ self._commit_removals()
if self is other:
self.data.clear()
else:
@@ -98,8 +154,12 @@
__and__ = intersection
def intersection_update(self, other):
+ if self._pending_removals:
+ self._commit_removals()
self.data.intersection_update(ref(item) for item in other)
def __iand__(self, other):
+ if self._pending_removals:
+ self._commit_removals()
self.data.intersection_update(ref(item) for item in other)
return self
@@ -127,11 +187,15 @@
__xor__ = symmetric_difference
def symmetric_difference_update(self, other):
+ if self._pending_removals:
+ self._commit_removals()
if self is other:
self.data.clear()
else:
self.data.symmetric_difference_update(ref(item) for item in other)
def __ixor__(self, other):
+ if self._pending_removals:
+ self._commit_removals()
if self is other:
self.data.clear()
else:
Modified: python/branches/py3k-cdecimal/Lib/cmd.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/cmd.py (original)
+++ python/branches/py3k-cdecimal/Lib/cmd.py Thu Jan 21 20:32:23 2010
@@ -278,19 +278,15 @@
return None
def get_names(self):
- # Inheritance says we have to look in class and
- # base classes; order is not important.
- names = []
- classes = [self.__class__]
- while classes:
- aclass = classes.pop(0)
- if aclass.__bases__:
- classes = classes + list(aclass.__bases__)
- names = names + dir(aclass)
- return names
+ # This method used to pull in base class attributes
+ # at a time dir() didn't do it yet.
+ return dir(self.__class__)
def complete_help(self, *args):
- return self.completenames(*args)
+ commands = set(self.completenames(*args))
+ topics = set(a[5:] for a in self.get_names()
+ if a.startswith('help_' + args[0]))
+ return list(commands | topics)
def do_help(self, arg):
if arg:
Modified: python/branches/py3k-cdecimal/Lib/distutils/ccompiler.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/distutils/ccompiler.py (original)
+++ python/branches/py3k-cdecimal/Lib/distutils/ccompiler.py Thu Jan 21 20:32:23 2010
@@ -9,11 +9,12 @@
import os
import re
-from distutils.errors import CompileError, LinkError, UnknownFileError
+from distutils.errors import (CompileError, LinkError, UnknownFileError,
+ DistutilsPlatformError, DistutilsModuleError)
from distutils.spawn import spawn
from distutils.file_util import move_file
from distutils.dir_util import mkpath
-from distutils.dep_util import newer_pairwise, newer_group
+from distutils.dep_util import newer_group
from distutils.util import split_quoted, execute
from distutils import log
@@ -314,10 +315,7 @@
def _setup_compile(self, outdir, macros, incdirs, sources, depends,
extra):
- """Process arguments and decide which source files to compile.
-
- Merges _fix_compile_args() and _prep_compile().
- """
+ """Process arguments and decide which source files to compile."""
if outdir is None:
outdir = self.output_dir
elif not isinstance(outdir, str):
@@ -346,41 +344,6 @@
output_dir=outdir)
assert len(objects) == len(sources)
- # XXX should redo this code to eliminate skip_source entirely.
- # XXX instead create build and issue skip messages inline
-
- if self.force:
- skip_source = {} # rebuild everything
- for source in sources:
- skip_source[source] = 0
- elif depends is None:
- # If depends is None, figure out which source files we
- # have to recompile according to a simplistic check. We
- # just compare the source and object file, no deep
- # dependency checking involving header files.
- skip_source = {} # rebuild everything
- for source in sources: # no wait, rebuild nothing
- skip_source[source] = 1
-
- n_sources, n_objects = newer_pairwise(sources, objects)
- for source in n_sources: # no really, only rebuild what's
- skip_source[source] = 0 # out-of-date
- else:
- # If depends is a list of files, then do a different
- # simplistic check. Assume that each object depends on
- # its source and all files in the depends list.
- skip_source = {}
- # L contains all the depends plus a spot at the end for a
- # particular source file
- L = depends[:] + [None]
- for i in range(len(objects)):
- source = sources[i]
- L[-1] = source
- if newer_group(L, objects[i]):
- skip_source[source] = 0
- else:
- skip_source[source] = 1
-
pp_opts = gen_preprocess_options(macros, incdirs)
build = {}
@@ -389,10 +352,7 @@
obj = objects[i]
ext = os.path.splitext(src)[1]
self.mkpath(os.path.dirname(obj))
- if skip_source[src]:
- log.debug("skipping %s (%s up-to-date)", src, obj)
- else:
- build[obj] = src, ext
+ build[obj] = (src, ext)
return macros, objects, extra, pp_opts, build
@@ -437,53 +397,6 @@
return output_dir, macros, include_dirs
- def _prep_compile(self, sources, output_dir, depends=None):
- """Decide which souce files must be recompiled.
-
- Determine the list of object files corresponding to 'sources',
- and figure out which ones really need to be recompiled.
- Return a list of all object files and a dictionary telling
- which source files can be skipped.
- """
- # Get the list of expected output (object) files
- objects = self.object_filenames(sources, output_dir=output_dir)
- assert len(objects) == len(sources)
-
- if self.force:
- skip_source = {} # rebuild everything
- for source in sources:
- skip_source[source] = 0
- elif depends is None:
- # If depends is None, figure out which source files we
- # have to recompile according to a simplistic check. We
- # just compare the source and object file, no deep
- # dependency checking involving header files.
- skip_source = {} # rebuild everything
- for source in sources: # no wait, rebuild nothing
- skip_source[source] = 1
-
- n_sources, n_objects = newer_pairwise(sources, objects)
- for source in n_sources: # no really, only rebuild what's
- skip_source[source] = 0 # out-of-date
- else:
- # If depends is a list of files, then do a different
- # simplistic check. Assume that each object depends on
- # its source and all files in the depends list.
- skip_source = {}
- # L contains all the depends plus a spot at the end for a
- # particular source file
- L = depends[:] + [None]
- for i in range(len(objects)):
- source = sources[i]
- L[-1] = source
- if newer_group(L, objects[i]):
- skip_source[source] = 0
- else:
- skip_source[source] = 1
-
- return objects, skip_source
-
-
def _fix_object_args(self, objects, output_dir):
"""Typecheck and fix up some arguments supplied to various methods.
Specifically: ensure that 'objects' is a list; if output_dir is
@@ -685,26 +598,15 @@
"""
pass
-
# values for target_desc parameter in link()
SHARED_OBJECT = "shared_object"
SHARED_LIBRARY = "shared_library"
EXECUTABLE = "executable"
- def link(self,
- target_desc,
- objects,
- output_filename,
- output_dir=None,
- libraries=None,
- library_dirs=None,
- runtime_library_dirs=None,
- export_symbols=None,
- debug=0,
- extra_preargs=None,
- extra_postargs=None,
- build_temp=None,
- target_lang=None):
+ def link(self, target_desc, objects, output_filename, output_dir=None,
+ libraries=None, library_dirs=None, runtime_library_dirs=None,
+ export_symbols=None, debug=0, extra_preargs=None,
+ extra_postargs=None, build_temp=None, target_lang=None):
"""Link a bunch of stuff together to create an executable or
shared library file.
@@ -753,19 +655,11 @@
# Old 'link_*()' methods, rewritten to use the new 'link()' method.
- def link_shared_lib(self,
- objects,
- output_libname,
- output_dir=None,
- libraries=None,
- library_dirs=None,
- runtime_library_dirs=None,
- export_symbols=None,
- debug=0,
- extra_preargs=None,
- extra_postargs=None,
- build_temp=None,
- target_lang=None):
+ def link_shared_lib(self, objects, output_libname, output_dir=None,
+ libraries=None, library_dirs=None,
+ runtime_library_dirs=None, export_symbols=None,
+ debug=0, extra_preargs=None, extra_postargs=None,
+ build_temp=None, target_lang=None):
self.link(CCompiler.SHARED_LIBRARY, objects,
self.library_filename(output_libname, lib_type='shared'),
output_dir,
@@ -774,19 +668,11 @@
extra_preargs, extra_postargs, build_temp, target_lang)
- def link_shared_object(self,
- objects,
- output_filename,
- output_dir=None,
- libraries=None,
- library_dirs=None,
- runtime_library_dirs=None,
- export_symbols=None,
- debug=0,
- extra_preargs=None,
- extra_postargs=None,
- build_temp=None,
- target_lang=None):
+ def link_shared_object(self, objects, output_filename, output_dir=None,
+ libraries=None, library_dirs=None,
+ runtime_library_dirs=None, export_symbols=None,
+ debug=0, extra_preargs=None, extra_postargs=None,
+ build_temp=None, target_lang=None):
self.link(CCompiler.SHARED_OBJECT, objects,
output_filename, output_dir,
libraries, library_dirs, runtime_library_dirs,
@@ -794,17 +680,10 @@
extra_preargs, extra_postargs, build_temp, target_lang)
- def link_executable(self,
- objects,
- output_progname,
- output_dir=None,
- libraries=None,
- library_dirs=None,
- runtime_library_dirs=None,
- debug=0,
- extra_preargs=None,
- extra_postargs=None,
- target_lang=None):
+ def link_executable(self, objects, output_progname, output_dir=None,
+ libraries=None, library_dirs=None,
+ runtime_library_dirs=None, debug=0, extra_preargs=None,
+ extra_postargs=None, target_lang=None):
self.link(CCompiler.EXECUTABLE, objects,
self.executable_filename(output_progname), output_dir,
libraries, library_dirs, runtime_library_dirs, None,
@@ -986,7 +865,7 @@
def move_file(self, src, dst):
return move_file(src, dst, dry_run=self.dry_run)
- def mkpath (self, name, mode=0o777):
+ def mkpath(self, name, mode=0o777):
mkpath(name, mode, dry_run=self.dry_run)
Modified: python/branches/py3k-cdecimal/Lib/distutils/tests/test_unixccompiler.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/distutils/tests/test_unixccompiler.py (original)
+++ python/branches/py3k-cdecimal/Lib/distutils/tests/test_unixccompiler.py Thu Jan 21 20:32:23 2010
@@ -82,6 +82,18 @@
sysconfig.get_config_var = gcv
self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo')
+ # GCC GNULD with fully qualified configuration prefix
+ # see #7617
+ sys.platform = 'bar'
+ def gcv(v):
+ if v == 'CC':
+ return 'x86_64-pc-linux-gnu-gcc-4.4.2'
+ elif v == 'GNULD':
+ return 'yes'
+ sysconfig.get_config_var = gcv
+ self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo')
+
+
# non-GCC GNULD
sys.platform = 'bar'
def gcv(v):
Modified: python/branches/py3k-cdecimal/Lib/distutils/unixccompiler.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/distutils/unixccompiler.py (original)
+++ python/branches/py3k-cdecimal/Lib/distutils/unixccompiler.py Thu Jan 21 20:32:23 2010
@@ -264,6 +264,9 @@
def library_dir_option(self, dir):
return "-L" + dir
+ def _is_gcc(self, compiler_name):
+ return "gcc" in compiler_name or "g++" in compiler_name
+
def runtime_library_dir_option(self, dir):
# XXX Hackish, at the very least. See Python bug #445902:
# http://sourceforge.net/tracker/index.php
@@ -283,12 +286,12 @@
# MacOSX's linker doesn't understand the -R flag at all
return "-L" + dir
elif sys.platform[:5] == "hp-ux":
- if "gcc" in compiler or "g++" in compiler:
+ if self._is_gcc(compiler):
return ["-Wl,+s", "-L" + dir]
return ["+s", "-L" + dir]
elif sys.platform[:7] == "irix646" or sys.platform[:6] == "osf1V5":
return ["-rpath", dir]
- elif compiler[:3] == "gcc" or compiler[:3] == "g++":
+ elif self._is_gcc(compiler):
# gcc on non-GNU systems does not need -Wl, but can
# use it anyway. Since distutils has always passed in
# -Wl whenever gcc was used in the past it is probably
Modified: python/branches/py3k-cdecimal/Lib/email/generator.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/email/generator.py (original)
+++ python/branches/py3k-cdecimal/Lib/email/generator.py Thu Jan 21 20:32:23 2010
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2007 Python Software Foundation
+# Copyright (C) 2001-2010 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig at python.org
@@ -215,6 +215,17 @@
print(file=self._fp)
self._fp.write(msg.epilogue)
+ def _handle_multipart_signed(self, msg):
+ # The contents of signed parts has to stay unmodified in order to keep
+ # the signature intact per RFC1847 2.1, so we disable header wrapping.
+ # RDM: This isn't enough to completely preserve the part, but it helps.
+ old_maxheaderlen = self._maxheaderlen
+ try:
+ self._maxheaderlen = 0
+ self._handle_multipart(msg)
+ finally:
+ self._maxheaderlen = old_maxheaderlen
+
def _handle_message_delivery_status(self, msg):
# We can't just write the headers directly to self's file object
# because this will leave an extra newline between the last header
Modified: python/branches/py3k-cdecimal/Lib/email/test/test_email.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/email/test/test_email.py (original)
+++ python/branches/py3k-cdecimal/Lib/email/test/test_email.py Thu Jan 21 20:32:23 2010
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2007 Python Software Foundation
+# Copyright (C) 2001-2010 Python Software Foundation
# Contact: email-sig at python.org
# email package unit tests
@@ -3387,6 +3387,44 @@
+# Tests to ensure that signed parts of an email are completely preserved, as
+# required by RFC1847 section 2.1. Note that these are incomplete, because the
+# email package does not currently always preserve the body. See issue 1670765.
+class TestSigned(TestEmailBase):
+
+ def _msg_and_obj(self, filename):
+ with openfile(findfile(filename)) as fp:
+ original = fp.read()
+ msg = email.message_from_string(original)
+ return original, msg
+
+ def _signed_parts_eq(self, original, result):
+ # Extract the first mime part of each message
+ import re
+ repart = re.compile(r'^--([^\n]+)\n(.*?)\n--\1$', re.S | re.M)
+ inpart = repart.search(original).group(2)
+ outpart = repart.search(result).group(2)
+ self.assertEqual(outpart, inpart)
+
+ def test_long_headers_as_string(self):
+ original, msg = self._msg_and_obj('msg_45.txt')
+ result = msg.as_string()
+ self._signed_parts_eq(original, result)
+
+ def test_long_headers_as_string_maxheaderlen(self):
+ original, msg = self._msg_and_obj('msg_45.txt')
+ result = msg.as_string(maxheaderlen=60)
+ self._signed_parts_eq(original, result)
+
+ def test_long_headers_flatten(self):
+ original, msg = self._msg_and_obj('msg_45.txt')
+ fp = StringIO()
+ Generator(fp).flatten(msg)
+ result = fp.getvalue()
+ self._signed_parts_eq(original, result)
+
+
+
def _testclasses():
mod = sys.modules[__name__]
return [getattr(mod, name) for name in dir(mod) if name.startswith('Test')]
Modified: python/branches/py3k-cdecimal/Lib/email/utils.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/email/utils.py (original)
+++ python/branches/py3k-cdecimal/Lib/email/utils.py Thu Jan 21 20:32:23 2010
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2009 Python Software Foundation
+# Copyright (C) 2001-2010 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig at python.org
Modified: python/branches/py3k-cdecimal/Lib/gzip.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/gzip.py (original)
+++ python/branches/py3k-cdecimal/Lib/gzip.py Thu Jan 21 20:32:23 2010
@@ -348,6 +348,15 @@
elif isize != (self.size & 0xffffffff):
raise IOError("Incorrect length of data produced")
+ # Gzip files can be padded with zeroes and still have archives.
+ # Consume all zero bytes and set the file position to the first
+ # non-zero byte. See http://www.gzip.org/#faq8
+ c = b"\x00"
+ while c == b"\x00":
+ c = self.fileobj.read(1)
+ if c:
+ self.fileobj.seek(-1, 1)
+
@property
def closed(self):
return self.fileobj is None
Modified: python/branches/py3k-cdecimal/Lib/idlelib/NEWS.txt
==============================================================================
--- python/branches/py3k-cdecimal/Lib/idlelib/NEWS.txt (original)
+++ python/branches/py3k-cdecimal/Lib/idlelib/NEWS.txt Thu Jan 21 20:32:23 2010
@@ -28,7 +28,7 @@
What's New in IDLE 2.7? (UNRELEASED, but merged into 3.1 releases above.)
=======================
-*Release date: XX-XXX-2009*
+*Release date: XX-XXX-2010*
- idle.py modified and simplified to better support developing experimental
versions of IDLE which are not installed in the standard location.
Modified: python/branches/py3k-cdecimal/Lib/logging/__init__.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/logging/__init__.py (original)
+++ python/branches/py3k-cdecimal/Lib/logging/__init__.py Thu Jan 21 20:32:23 2010
@@ -18,7 +18,7 @@
Logging package for Python. Based on PEP 282 and comments thereto in
comp.lang.python, and influenced by Apache's log4j system.
-Copyright (C) 2001-2009 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2010 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging' and log away!
"""
Modified: python/branches/py3k-cdecimal/Lib/pickle.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/pickle.py (original)
+++ python/branches/py3k-cdecimal/Lib/pickle.py Thu Jan 21 20:32:23 2010
@@ -1269,50 +1269,14 @@
b'\x7f'
>>>
"""
-
if x == 0:
return b''
- if x > 0:
- ashex = hex(x)
- assert ashex.startswith("0x")
- njunkchars = 2 + ashex.endswith('L')
- nibbles = len(ashex) - njunkchars
- if nibbles & 1:
- # need an even # of nibbles for unhexlify
- ashex = "0x0" + ashex[2:]
- elif int(ashex[2], 16) >= 8:
- # "looks negative", so need a byte of sign bits
- ashex = "0x00" + ashex[2:]
- else:
- # Build the 256's-complement: (1L << nbytes) + x. The trick is
- # to find the number of bytes in linear time (although that should
- # really be a constant-time task).
- ashex = hex(-x)
- assert ashex.startswith("0x")
- njunkchars = 2 + ashex.endswith('L')
- nibbles = len(ashex) - njunkchars
- if nibbles & 1:
- # Extend to a full byte.
- nibbles += 1
- nbits = nibbles * 4
- x += 1 << nbits
- assert x > 0
- ashex = hex(x)
- njunkchars = 2 + ashex.endswith('L')
- newnibbles = len(ashex) - njunkchars
- if newnibbles < nibbles:
- ashex = "0x" + "0" * (nibbles - newnibbles) + ashex[2:]
- if int(ashex[2], 16) < 8:
- # "looks positive", so need a byte of sign bits
- ashex = "0xff" + ashex[2:]
-
- if ashex.endswith('L'):
- ashex = ashex[2:-1]
- else:
- ashex = ashex[2:]
- assert len(ashex) & 1 == 0, (x, ashex)
- binary = _binascii.unhexlify(ashex)
- return bytes(binary[::-1])
+ nbytes = (x.bit_length() >> 3) + 1
+ result = x.to_bytes(nbytes, byteorder='little', signed=True)
+ if x < 0 and nbytes > 1:
+ if result[-1] == 0xff and (result[-2] & 0x80) != 0:
+ result = result[:-1]
+ return result
def decode_long(data):
r"""Decode a long from a two's complement little-endian binary string.
@@ -1332,15 +1296,7 @@
>>> decode_long(b"\x7f")
127
"""
-
- nbytes = len(data)
- if nbytes == 0:
- return 0
- ashex = _binascii.hexlify(data[::-1])
- n = int(ashex, 16) # quadratic time before Python 2.3; linear now
- if data[-1] >= 0x80:
- n -= 1 << (nbytes * 8)
- return n
+ return int.from_bytes(data, byteorder='little', signed=True)
# Use the faster _pickle if possible
try:
Modified: python/branches/py3k-cdecimal/Lib/platform.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/platform.py (original)
+++ python/branches/py3k-cdecimal/Lib/platform.py Thu Jan 21 20:32:23 2010
@@ -90,7 +90,7 @@
__copyright__ = """
Copyright (c) 1999-2000, Marc-Andre Lemburg; mailto:mal at lemburg.com
- Copyright (c) 2000-2009, eGenix.com Software GmbH; mailto:info at egenix.com
+ Copyright (c) 2000-2010, eGenix.com Software GmbH; mailto:info at egenix.com
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee or royalty is hereby granted,
Modified: python/branches/py3k-cdecimal/Lib/ssl.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/ssl.py (original)
+++ python/branches/py3k-cdecimal/Lib/ssl.py Thu Jan 21 20:32:23 2010
@@ -304,7 +304,7 @@
self._sslobj = None
socket.shutdown(self, how)
- def unwrap (self):
+ def unwrap(self):
if self._sslobj:
s = self._sslobj.shutdown()
self._sslobj = None
Modified: python/branches/py3k-cdecimal/Lib/test/crashers/bogus_code_obj.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/crashers/bogus_code_obj.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/crashers/bogus_code_obj.py Thu Jan 21 20:32:23 2010
@@ -14,6 +14,6 @@
import types
-co = types.CodeType(0, 0, 0, 0, '\x04\x71\x00\x00', (),
- (), (), '', '', 1, '')
+co = types.CodeType(0, 0, 0, 0, 0, b'\x04\x71\x00\x00',
+ (), (), (), '', '', 1, b'')
exec(co)
Modified: python/branches/py3k-cdecimal/Lib/test/floating_points.txt
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/floating_points.txt (original)
+++ python/branches/py3k-cdecimal/Lib/test/floating_points.txt Thu Jan 21 20:32:23 2010
@@ -1019,3 +1019,10 @@
+43723334984997307E-26
+10182419849537963E-24
-93501703572661982E-26
+
+# A value that caused a crash in debug builds for Python >= 2.7, 3.1
+# See http://bugs.python.org/issue7632
+2183167012312112312312.23538020374420446192e-370
+
+# Another value designed to test a corner case of Python's strtod code.
+0.99999999999999999999999999999999999999999e+23
Modified: python/branches/py3k-cdecimal/Lib/test/https_svn_python_org_root.pem
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/https_svn_python_org_root.pem (original)
+++ python/branches/py3k-cdecimal/Lib/test/https_svn_python_org_root.pem Thu Jan 21 20:32:23 2010
@@ -1,26 +1,41 @@
-----BEGIN CERTIFICATE-----
-MIIEdDCCA1ygAwIBAgIQRL4Mi1AAJLQR0zYq/mUK/TANBgkqhkiG9w0BAQUFADCB
-lzELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAlVUMRcwFQYDVQQHEw5TYWx0IExha2Ug
-Q2l0eTEeMBwGA1UEChMVVGhlIFVTRVJUUlVTVCBOZXR3b3JrMSEwHwYDVQQLExho
-dHRwOi8vd3d3LnVzZXJ0cnVzdC5jb20xHzAdBgNVBAMTFlVUTi1VU0VSRmlyc3Qt
-SGFyZHdhcmUwHhcNOTkwNzA5MTgxMDQyWhcNMTkwNzA5MTgxOTIyWjCBlzELMAkG
-A1UEBhMCVVMxCzAJBgNVBAgTAlVUMRcwFQYDVQQHEw5TYWx0IExha2UgQ2l0eTEe
-MBwGA1UEChMVVGhlIFVTRVJUUlVTVCBOZXR3b3JrMSEwHwYDVQQLExhodHRwOi8v
-d3d3LnVzZXJ0cnVzdC5jb20xHzAdBgNVBAMTFlVUTi1VU0VSRmlyc3QtSGFyZHdh
-cmUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCx98M4P7Sof885glFn
-0G2f0v9Y8+efK+wNiVSZuTiZFvfgIXlIwrthdBKWHTxqctU8EGc6Oe0rE81m65UJ
-M6Rsl7HoxuzBdXmcRl6Nq9Bq/bkqVRcQVLMZ8Jr28bFdtqdt++BxF2uiiPsA3/4a
-MXcMmgF6sTLjKwEHOG7DpV4jvEWbe1DByTCP2+UretNb+zNAHqDVmBe8i4fDidNd
-oI6yqqr2jmmIBsX6iSHzCJ1pLgkzmykNRg+MzEk0sGlRvfkGzWitZky8PqxhvQqI
-DsjfPe58BEydCl5rkdbux+0ojatNh4lz0G6k0B4WixThdkQDf2Os5M1JnMWS9Ksy
-oUhbAgMBAAGjgbkwgbYwCwYDVR0PBAQDAgHGMA8GA1UdEwEB/wQFMAMBAf8wHQYD
-VR0OBBYEFKFyXyYbKJhDlV0HN9WFlp1L0sNFMEQGA1UdHwQ9MDswOaA3oDWGM2h0
-dHA6Ly9jcmwudXNlcnRydXN0LmNvbS9VVE4tVVNFUkZpcnN0LUhhcmR3YXJlLmNy
-bDAxBgNVHSUEKjAoBggrBgEFBQcDAQYIKwYBBQUHAwUGCCsGAQUFBwMGBggrBgEF
-BQcDBzANBgkqhkiG9w0BAQUFAAOCAQEARxkP3nTGmZev/K0oXnWO6y1n7k57K9cM
-//bey1WiCuFMVGWTYGufEpytXoMs61quwOQt9ABjHbjAbPLPSbtNk28Gpgoiskli
-CE7/yMgUsogWXecB5BKV5UU0s4tpvc+0hY91UZ59Ojg6FEgSxvunOxqNDYJAB+gE
-CJChicsZUN/KHAG8HQQZexB2lzvukJDKxA4fFm517zP4029bHpbj4HR3dHuKom4t
-3XbWOTCC8KucUvIqx69JXn7HaOWCgchqJ/kniCrVWFCVH/A7HFe7fRQ5YiuayZSS
-KqMiDP+JJn1fIytH1xUdqWqeUQ0qUZ6B+dQ7XnASfxAynB67nfhmqA==
------END CERTIFICATE-----
\ No newline at end of file
+MIIHPTCCBSWgAwIBAgIBADANBgkqhkiG9w0BAQQFADB5MRAwDgYDVQQKEwdSb290
+IENBMR4wHAYDVQQLExVodHRwOi8vd3d3LmNhY2VydC5vcmcxIjAgBgNVBAMTGUNB
+IENlcnQgU2lnbmluZyBBdXRob3JpdHkxITAfBgkqhkiG9w0BCQEWEnN1cHBvcnRA
+Y2FjZXJ0Lm9yZzAeFw0wMzAzMzAxMjI5NDlaFw0zMzAzMjkxMjI5NDlaMHkxEDAO
+BgNVBAoTB1Jvb3QgQ0ExHjAcBgNVBAsTFWh0dHA6Ly93d3cuY2FjZXJ0Lm9yZzEi
+MCAGA1UEAxMZQ0EgQ2VydCBTaWduaW5nIEF1dGhvcml0eTEhMB8GCSqGSIb3DQEJ
+ARYSc3VwcG9ydEBjYWNlcnQub3JnMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC
+CgKCAgEAziLA4kZ97DYoB1CW8qAzQIxL8TtmPzHlawI229Z89vGIj053NgVBlfkJ
+8BLPRoZzYLdufujAWGSuzbCtRRcMY/pnCujW0r8+55jE8Ez64AO7NV1sId6eINm6
+zWYyN3L69wj1x81YyY7nDl7qPv4coRQKFWyGhFtkZip6qUtTefWIonvuLwphK42y
+fk1WpRPs6tqSnqxEQR5YYGUFZvjARL3LlPdCfgv3ZWiYUQXw8wWRBB0bF4LsyFe7
+w2t6iPGwcswlWyCR7BYCEo8y6RcYSNDHBS4CMEK4JZwFaz+qOqfrU0j36NK2B5jc
+G8Y0f3/JHIJ6BVgrCFvzOKKrF11myZjXnhCLotLddJr3cQxyYN/Nb5gznZY0dj4k
+epKwDpUeb+agRThHqtdB7Uq3EvbXG4OKDy7YCbZZ16oE/9KTfWgu3YtLq1i6L43q
+laegw1SJpfvbi1EinbLDvhG+LJGGi5Z4rSDTii8aP8bQUWWHIbEZAWV/RRyH9XzQ
+QUxPKZgh/TMfdQwEUfoZd9vUFBzugcMd9Zi3aQaRIt0AUMyBMawSB3s42mhb5ivU
+fslfrejrckzzAeVLIL+aplfKkQABi6F1ITe1Yw1nPkZPcCBnzsXWWdsC4PDSy826
+YreQQejdIOQpvGQpQsgi3Hia/0PsmBsJUUtaWsJx8cTLc6nloQsCAwEAAaOCAc4w
+ggHKMB0GA1UdDgQWBBQWtTIb1Mfz4OaO873SsDrusjkY0TCBowYDVR0jBIGbMIGY
+gBQWtTIb1Mfz4OaO873SsDrusjkY0aF9pHsweTEQMA4GA1UEChMHUm9vdCBDQTEe
+MBwGA1UECxMVaHR0cDovL3d3dy5jYWNlcnQub3JnMSIwIAYDVQQDExlDQSBDZXJ0
+IFNpZ25pbmcgQXV0aG9yaXR5MSEwHwYJKoZIhvcNAQkBFhJzdXBwb3J0QGNhY2Vy
+dC5vcmeCAQAwDwYDVR0TAQH/BAUwAwEB/zAyBgNVHR8EKzApMCegJaAjhiFodHRw
+czovL3d3dy5jYWNlcnQub3JnL3Jldm9rZS5jcmwwMAYJYIZIAYb4QgEEBCMWIWh0
+dHBzOi8vd3d3LmNhY2VydC5vcmcvcmV2b2tlLmNybDA0BglghkgBhvhCAQgEJxYl
+aHR0cDovL3d3dy5jYWNlcnQub3JnL2luZGV4LnBocD9pZD0xMDBWBglghkgBhvhC
+AQ0ESRZHVG8gZ2V0IHlvdXIgb3duIGNlcnRpZmljYXRlIGZvciBGUkVFIGhlYWQg
+b3ZlciB0byBodHRwOi8vd3d3LmNhY2VydC5vcmcwDQYJKoZIhvcNAQEEBQADggIB
+ACjH7pyCArpcgBLKNQodgW+JapnM8mgPf6fhjViVPr3yBsOQWqy1YPaZQwGjiHCc
+nWKdpIevZ1gNMDY75q1I08t0AoZxPuIrA2jxNGJARjtT6ij0rPtmlVOKTV39O9lg
+18p5aTuxZZKmxoGCXJzN600BiqXfEVWqFcofN8CCmHBh22p8lqOOLlQ+TyGpkO/c
+gr/c6EWtTZBzCDyUZbAEmXZ/4rzCahWqlwQ3JNgelE5tDlG+1sSPypZt90Pf6DBl
+Jzt7u0NDY8RD97LsaMzhGY4i+5jhe1o+ATc7iwiwovOVThrLm82asduycPAtStvY
+sONvRUgzEv/+PDIqVPfE94rwiCPCR/5kenHA0R6mY7AHfqQv0wGP3J8rtsYIqQ+T
+SCX8Ev2fQtzzxD72V7DX3WnRBnc0CkvSyqD/HMaMyRa+xMwyN2hzXwj7UfdJUzYF
+CpUCTPJ5GhD22Dp1nPMd8aINcGeGG7MW9S/lpOt5hvk9C8JzC6WZrG/8Z7jlLwum
+GCSNe9FINSkYQKyTYOGWhlC0elnYjyELn8+CkcY7v2vcB5G5l1YjqrZslMZIBjzk
+zk6q5PYvCdxTby78dOs6Y5nCpqyJvKeyRKANihDjbPIky/qbn3BHLt4Ui9SyIAmW
+omTxJBzcoTWcFbLUvFUufQb1nA5V9FrWk9p2rSVzTMVD
+-----END CERTIFICATE-----
Modified: python/branches/py3k-cdecimal/Lib/test/pickletester.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/pickletester.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/pickletester.py Thu Jan 21 20:32:23 2010
@@ -1139,6 +1139,9 @@
# Test issue4298
s = bytes([0x58, 0, 0, 0, 0x54])
self.assertRaises(EOFError, pickle.loads, s)
+ # Test issue7455
+ s = b'0'
+ self.assertRaises(pickle.UnpicklingError, pickle.loads, s)
class AbstractPersistentPicklerTests(unittest.TestCase):
Modified: python/branches/py3k-cdecimal/Lib/test/regrtest.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/regrtest.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/regrtest.py Thu Jan 21 20:32:23 2010
@@ -159,16 +159,6 @@
import unittest
from inspect import isabstract
-# I see no other way to suppress these warnings;
-# putting them in test_grammar.py has no effect:
-warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
- ".*test.test_grammar$")
-if sys.maxsize > 0x7fffffff:
- # Also suppress them in <string>, because for 64-bit platforms,
- # that's where test_grammar.py hides them.
- warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
- "<string>")
-
# Ignore ImportWarnings that only occur in the source tree,
# (because of modules with the same name as source-directories in Modules/)
for mod in ("ctypes", "gzip", "zipfile", "tarfile", "encodings.zlib_codec",
Modified: python/branches/py3k-cdecimal/Lib/test/test_bigmem.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_bigmem.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_bigmem.py Thu Jan 21 20:32:23 2010
@@ -519,12 +519,12 @@
edge = _('-') * (size // 2)
s = _('').join([edge, SUBSTR, edge])
del edge
- self.assertTrue(SUBSTR in s)
+ self.assertIn(SUBSTR, s)
self.assertFalse(SUBSTR * 2 in s)
- self.assertTrue(_('-') in s)
+ self.assertIn(_('-'), s)
self.assertFalse(_('a') in s)
s += _('a')
- self.assertTrue(_('a') in s)
+ self.assertIn(_('a'), s)
@bigmemtest(minsize=_2G + 10, memuse=2)
def test_compare(self, size):
@@ -768,7 +768,7 @@
def test_contains(self, size):
t = (1, 2, 3, 4, 5) * size
self.assertEquals(len(t), size * 5)
- self.assertTrue(5 in t)
+ self.assertIn(5, t)
self.assertFalse((1, 2, 3, 4, 5) in t)
self.assertFalse(0 in t)
@@ -917,7 +917,7 @@
def test_contains(self, size):
l = [1, 2, 3, 4, 5] * size
self.assertEquals(len(l), size * 5)
- self.assertTrue(5 in l)
+ self.assertIn(5, l)
self.assertFalse([1, 2, 3, 4, 5] in l)
self.assertFalse(0 in l)
Modified: python/branches/py3k-cdecimal/Lib/test/test_binascii.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_binascii.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_binascii.py Thu Jan 21 20:32:23 2010
@@ -3,14 +3,27 @@
from test import support
import unittest
import binascii
+import array
+
+# Note: "*_hex" functions are aliases for "(un)hexlify"
+b2a_functions = ['b2a_base64', 'b2a_hex', 'b2a_hqx', 'b2a_qp', 'b2a_uu',
+ 'hexlify', 'rlecode_hqx']
+a2b_functions = ['a2b_base64', 'a2b_hex', 'a2b_hqx', 'a2b_qp', 'a2b_uu',
+ 'unhexlify', 'rledecode_hqx']
+all_functions = a2b_functions + b2a_functions + ['crc32', 'crc_hqx']
+
class BinASCIITest(unittest.TestCase):
+ type2test = bytes
# Create binary test data
- data = b"The quick brown fox jumps over the lazy dog.\r\n"
+ rawdata = b"The quick brown fox jumps over the lazy dog.\r\n"
# Be slow so we don't depend on other modules
- data += bytes(range(256))
- data += b"\r\nHello world.\n"
+ rawdata += bytes(range(256))
+ rawdata += b"\r\nHello world.\n"
+
+ def setUp(self):
+ self.data = self.type2test(self.rawdata)
def test_exceptions(self):
# Check module exceptions
@@ -19,32 +32,47 @@
def test_functions(self):
# Check presence of all functions
- funcs = []
- for suffix in "base64", "hqx", "uu", "hex":
- prefixes = ["a2b_", "b2a_"]
- if suffix == "hqx":
- prefixes.extend(["crc_", "rlecode_", "rledecode_"])
- for prefix in prefixes:
- name = prefix + suffix
- self.assertTrue(hasattr(getattr(binascii, name), '__call__'))
- self.assertRaises(TypeError, getattr(binascii, name))
- for name in ("hexlify", "unhexlify"):
+ for name in all_functions:
self.assertTrue(hasattr(getattr(binascii, name), '__call__'))
self.assertRaises(TypeError, getattr(binascii, name))
+ def test_returned_value(self):
+ # Limit to the minimum of all limits (b2a_uu)
+ MAX_ALL = 45
+ raw = self.rawdata[:MAX_ALL]
+ for fa, fb in zip(a2b_functions, b2a_functions):
+ a2b = getattr(binascii, fa)
+ b2a = getattr(binascii, fb)
+ try:
+ a = b2a(self.type2test(raw))
+ res = a2b(self.type2test(a))
+ except Exception as err:
+ self.fail("{}/{} conversion raises {!r}".format(fb, fa, err))
+ if fb == 'b2a_hqx':
+ # b2a_hqx returns a tuple
+ res, _ = res
+ self.assertEqual(res, raw, "{}/{} conversion: "
+ "{!r} != {!r}".format(fb, fa, res, raw))
+ self.assertIsInstance(res, bytes)
+ self.assertIsInstance(a, bytes)
+ self.assertLess(max(c for c in a), 128)
+ self.assertIsInstance(binascii.crc_hqx(raw, 0), int)
+ self.assertIsInstance(binascii.crc32(raw), int)
+
def test_base64valid(self):
# Test base64 with valid data
MAX_BASE64 = 57
lines = []
- for i in range(0, len(self.data), MAX_BASE64):
- b = self.data[i:i+MAX_BASE64]
+ for i in range(0, len(self.rawdata), MAX_BASE64):
+ b = self.type2test(self.rawdata[i:i+MAX_BASE64])
a = binascii.b2a_base64(b)
lines.append(a)
res = bytes()
for line in lines:
- b = binascii.a2b_base64(line)
+ a = self.type2test(line)
+ b = binascii.a2b_base64(a)
res += b
- self.assertEqual(res, self.data)
+ self.assertEqual(res, self.rawdata)
def test_base64invalid(self):
# Test base64 with random invalid characters sprinkled throughout
@@ -52,7 +80,7 @@
MAX_BASE64 = 57
lines = []
for i in range(0, len(self.data), MAX_BASE64):
- b = self.data[i:i+MAX_BASE64]
+ b = self.type2test(self.rawdata[i:i+MAX_BASE64])
a = binascii.b2a_base64(b)
lines.append(a)
@@ -74,26 +102,28 @@
return res + noise + line
res = bytearray()
for line in map(addnoise, lines):
- b = binascii.a2b_base64(line)
+ a = self.type2test(line)
+ b = binascii.a2b_base64(a)
res += b
- self.assertEqual(res, self.data)
+ self.assertEqual(res, self.rawdata)
# Test base64 with just invalid characters, which should return
# empty strings. TBD: shouldn't it raise an exception instead ?
- self.assertEqual(binascii.a2b_base64(fillers), b'')
+ self.assertEqual(binascii.a2b_base64(self.type2test(fillers)), b'')
def test_uu(self):
MAX_UU = 45
lines = []
for i in range(0, len(self.data), MAX_UU):
- b = self.data[i:i+MAX_UU]
+ b = self.type2test(self.rawdata[i:i+MAX_UU])
a = binascii.b2a_uu(b)
lines.append(a)
res = bytes()
for line in lines:
- b = binascii.a2b_uu(line)
+ a = self.type2test(line)
+ b = binascii.a2b_uu(a)
res += b
- self.assertEqual(res, self.data)
+ self.assertEqual(res, self.rawdata)
self.assertEqual(binascii.a2b_uu(b"\x7f"), b"\x00"*31)
self.assertEqual(binascii.a2b_uu(b"\x80"), b"\x00"*32)
@@ -103,20 +133,31 @@
self.assertRaises(binascii.Error, binascii.b2a_uu, 46*b"!")
+ # Issue #7701 (crash on a pydebug build)
+ self.assertEqual(binascii.b2a_uu(b'x'), b'!> \n')
+
def test_crc32(self):
- crc = binascii.crc32(b"Test the CRC-32 of")
- crc = binascii.crc32(b" this string.", crc)
+ crc = binascii.crc32(self.type2test(b"Test the CRC-32 of"))
+ crc = binascii.crc32(self.type2test(b" this string."), crc)
self.assertEqual(crc, 1571220330)
self.assertRaises(TypeError, binascii.crc32)
- # The hqx test is in test_binhex.py
+ def test_hqx(self):
+ # Perform binhex4 style RLE-compression
+ # Then calculate the hexbin4 binary-to-ASCII translation
+ rle = binascii.rlecode_hqx(self.data)
+ a = binascii.b2a_hqx(self.type2test(rle))
+ b, _ = binascii.a2b_hqx(self.type2test(a))
+ res = binascii.rledecode_hqx(b)
+
+ self.assertEqual(res, self.rawdata)
def test_hex(self):
# test hexlification
s = b'{s\005\000\000\000worldi\002\000\000\000s\005\000\000\000helloi\001\000\000\0000'
- t = binascii.b2a_hex(s)
- u = binascii.a2b_hex(t)
+ t = binascii.b2a_hex(self.type2test(s))
+ u = binascii.a2b_hex(self.type2test(t))
self.assertEqual(s, u)
self.assertRaises(binascii.Error, binascii.a2b_hex, t[:-1])
self.assertRaises(binascii.Error, binascii.a2b_hex, t[:-1] + b'q')
@@ -157,16 +198,17 @@
def test_empty_string(self):
# A test for SF bug #1022953. Make sure SystemError is not raised.
- for n in ['b2a_qp', 'a2b_hex', 'b2a_base64', 'a2b_uu', 'a2b_qp',
- 'b2a_hex', 'unhexlify', 'hexlify', 'crc32', 'b2a_hqx',
- 'a2b_hqx', 'a2b_base64', 'rlecode_hqx', 'b2a_uu',
- 'rledecode_hqx']:
- f = getattr(binascii, n)
+ empty = self.type2test(b'')
+ for func in all_functions:
+ if func == 'crc_hqx':
+ # crc_hqx needs 2 arguments
+ binascii.crc_hqx(empty, 0)
+ continue
+ f = getattr(binascii, func)
try:
- f(b'')
- except SystemError as err:
- self.fail("%s(b'') raises SystemError: %s" % (n, err))
- binascii.crc_hqx(b'', 0)
+ f(empty)
+ except Exception as err:
+ self.fail("{}({!r}) raises {!r}".format(func, empty, err))
def test_no_binary_strings(self):
# b2a_ must not accept strings
@@ -176,8 +218,25 @@
binascii.crc_hqx, binascii.crc32):
self.assertRaises(TypeError, f, "test")
+
+class ArrayBinASCIITest(BinASCIITest):
+ def type2test(self, s):
+ return array.array('B', list(s))
+
+
+class BytearrayBinASCIITest(BinASCIITest):
+ type2test = bytearray
+
+
+class MemoryviewBinASCIITest(BinASCIITest):
+ type2test = memoryview
+
+
def test_main():
- support.run_unittest(BinASCIITest)
+ support.run_unittest(BinASCIITest,
+ ArrayBinASCIITest,
+ BytearrayBinASCIITest,
+ MemoryviewBinASCIITest)
if __name__ == "__main__":
test_main()
Modified: python/branches/py3k-cdecimal/Lib/test/test_builtin.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_builtin.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_builtin.py Thu Jan 21 20:32:23 2010
@@ -248,11 +248,11 @@
# dir() - local scope
local_var = 1
- self.assertTrue('local_var' in dir())
+ self.assertIn('local_var', dir())
# dir(module)
import sys
- self.assertTrue('exit' in dir(sys))
+ self.assertIn('exit', dir(sys))
# dir(module_with_invalid__dict__)
import types
@@ -262,8 +262,8 @@
self.assertRaises(TypeError, dir, f)
# dir(type)
- self.assertTrue("strip" in dir(str))
- self.assertTrue("__mro__" not in dir(str))
+ self.assertIn("strip", dir(str))
+ self.assertNotIn("__mro__", dir(str))
# dir(obj)
class Foo(object):
@@ -272,13 +272,13 @@
self.y = 8
self.z = 9
f = Foo()
- self.assertTrue("y" in dir(f))
+ self.assertIn("y", dir(f))
# dir(obj_no__dict__)
class Foo(object):
__slots__ = []
f = Foo()
- self.assertTrue("__repr__" in dir(f))
+ self.assertIn("__repr__", dir(f))
# dir(obj_no__class__with__dict__)
# (an ugly trick to cause getattr(f, "__class__") to fail)
@@ -287,8 +287,8 @@
def __init__(self):
self.bar = "wow"
f = Foo()
- self.assertTrue("__repr__" not in dir(f))
- self.assertTrue("bar" in dir(f))
+ self.assertNotIn("__repr__", dir(f))
+ self.assertIn("bar", dir(f))
# dir(obj_using __dir__)
class Foo(object):
@@ -914,18 +914,18 @@
self.assertEqual(list(range(a+4, a, -2)), [a+4, a+2])
seq = list(range(a, b, c))
- self.assertTrue(a in seq)
- self.assertTrue(b not in seq)
+ self.assertIn(a, seq)
+ self.assertNotIn(b, seq)
self.assertEqual(len(seq), 2)
seq = list(range(b, a, -c))
- self.assertTrue(b in seq)
- self.assertTrue(a not in seq)
+ self.assertIn(b, seq)
+ self.assertNotIn(a, seq)
self.assertEqual(len(seq), 2)
seq = list(range(-a, -b, -c))
- self.assertTrue(-a in seq)
- self.assertTrue(-b not in seq)
+ self.assertIn(-a, seq)
+ self.assertNotIn(-b, seq)
self.assertEqual(len(seq), 2)
self.assertRaises(TypeError, range)
Modified: python/branches/py3k-cdecimal/Lib/test/test_bytes.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_bytes.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_bytes.py Thu Jan 21 20:32:23 2010
@@ -38,6 +38,13 @@
self.assertEqual(type(b), self.type2test)
self.assertEqual(b.__class__, self.type2test)
+ def test_copy(self):
+ a = self.type2test(b"abcd")
+ for copy_method in (copy.copy, copy.deepcopy):
+ b = copy_method(a)
+ self.assertEqual(a, b)
+ self.assertEqual(type(a), type(b))
+
def test_empty_sequence(self):
b = self.type2test()
self.assertEqual(len(b), 0)
@@ -222,8 +229,8 @@
def test_contains(self):
b = self.type2test(b"abc")
- self.assertTrue(ord('a') in b)
- self.assertTrue(int(ord('a')) in b)
+ self.assertIn(ord('a'), b)
+ self.assertIn(int(ord('a')), b)
self.assertFalse(200 in b)
self.assertFalse(200 in b)
self.assertRaises(ValueError, lambda: 300 in b)
@@ -232,13 +239,13 @@
self.assertRaises(TypeError, lambda: float(ord('a')) in b)
self.assertRaises(TypeError, lambda: "a" in b)
for f in bytes, bytearray:
- self.assertTrue(f(b"") in b)
- self.assertTrue(f(b"a") in b)
- self.assertTrue(f(b"b") in b)
- self.assertTrue(f(b"c") in b)
- self.assertTrue(f(b"ab") in b)
- self.assertTrue(f(b"bc") in b)
- self.assertTrue(f(b"abc") in b)
+ self.assertIn(f(b""), b)
+ self.assertIn(f(b"a"), b)
+ self.assertIn(f(b"b"), b)
+ self.assertIn(f(b"c"), b)
+ self.assertIn(f(b"ab"), b)
+ self.assertIn(f(b"bc"), b)
+ self.assertIn(f(b"abc"), b)
self.assertFalse(f(b"ac") in b)
self.assertFalse(f(b"d") in b)
self.assertFalse(f(b"dab") in b)
@@ -270,13 +277,6 @@
self.assertEqual(self.type2test(b".").join([b"ab", b"cd"]), b"ab.cd")
# XXX more...
- def test_index(self):
- b = self.type2test(b'parrot')
- self.assertEqual(b.index('p'), 0)
- self.assertEqual(b.index('rr'), 2)
- self.assertEqual(b.index('t'), 5)
- self.assertRaises(ValueError, lambda: b.index('w'))
-
def test_count(self):
b = self.type2test(b'mississippi')
self.assertEqual(b.count(b'i'), 4)
@@ -362,6 +362,10 @@
def test_split_string_error(self):
self.assertRaises(TypeError, self.type2test(b'a b').split, ' ')
+ def test_split_unicodewhitespace(self):
+ b = self.type2test(b"\x09\x0A\x0B\x0C\x0D\x1C\x1D\x1E\x1F")
+ self.assertEqual(b.split(), [b'\x1c\x1d\x1e\x1f'])
+
def test_rsplit(self):
b = self.type2test(b'mississippi')
self.assertEqual(b.rsplit(b'i'), [b'm', b'ss', b'ss', b'pp', b''])
@@ -385,18 +389,18 @@
def test_rsplit_unicodewhitespace(self):
b = self.type2test(b"\x09\x0A\x0B\x0C\x0D\x1C\x1D\x1E\x1F")
- self.assertEqual(b.split(), [b'\x1c\x1d\x1e\x1f'])
self.assertEqual(b.rsplit(), [b'\x1c\x1d\x1e\x1f'])
def test_partition(self):
b = self.type2test(b'mississippi')
self.assertEqual(b.partition(b'ss'), (b'mi', b'ss', b'issippi'))
- self.assertEqual(b.rpartition(b'w'), (b'', b'', b'mississippi'))
+ self.assertEqual(b.partition(b'w'), (b'mississippi', b'', b''))
def test_rpartition(self):
b = self.type2test(b'mississippi')
self.assertEqual(b.rpartition(b'ss'), (b'missi', b'ss', b'ippi'))
self.assertEqual(b.rpartition(b'i'), (b'mississipp', b'i', b''))
+ self.assertEqual(b.rpartition(b'w'), (b'', b'', b'mississippi'))
def test_pickling(self):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
@@ -813,6 +817,14 @@
self.assertRaises(BufferError, delslice)
self.assertEquals(b, orig)
+ def test_empty_bytearray(self):
+ # Issue #7561: operations on empty bytearrays could crash in many
+ # situations, due to a fragile implementation of the
+ # PyByteArray_AS_STRING() C macro.
+ self.assertRaises(ValueError, int, bytearray(b''))
+ self.assertRaises((ValueError, OSError), os.mkdir, bytearray(b''))
+
+
class AssortedBytesTest(unittest.TestCase):
#
# Test various combinations of bytes and bytearray
@@ -968,7 +980,13 @@
self.assertEqual(val, newval)
self.assertTrue(val is not newval,
methname+' returned self on a mutable object')
-
+ for expr in ('val.split()[0]', 'val.rsplit()[0]',
+ 'val.partition(b".")[0]', 'val.rpartition(b".")[2]',
+ 'val.splitlines()[0]', 'val.replace(b"", b"")'):
+ newval = eval(expr)
+ self.assertEqual(val, newval)
+ self.assertTrue(val is not newval,
+ expr+' returned val on a mutable object')
class FixedStringTest(test.string_tests.BaseTest):
@@ -996,17 +1014,14 @@
type2test = bytes
-class ByteArraySubclass(bytearray):
- pass
-
-class ByteArraySubclassTest(unittest.TestCase):
+class SubclassTest(unittest.TestCase):
def test_basic(self):
- self.assertTrue(issubclass(ByteArraySubclass, bytearray))
- self.assertTrue(isinstance(ByteArraySubclass(), bytearray))
+ self.assertTrue(issubclass(self.subclass2test, self.type2test))
+ self.assertTrue(isinstance(self.subclass2test(), self.type2test))
a, b = b"abcd", b"efgh"
- _a, _b = ByteArraySubclass(a), ByteArraySubclass(b)
+ _a, _b = self.subclass2test(a), self.subclass2test(b)
# test comparison operators with subclass instances
self.assertTrue(_a == _a)
@@ -1029,19 +1044,19 @@
# Make sure join returns a NEW object for single item sequences
# involving a subclass.
# Make sure that it is of the appropriate type.
- s1 = ByteArraySubclass(b"abcd")
- s2 = bytearray().join([s1])
+ s1 = self.subclass2test(b"abcd")
+ s2 = self.type2test().join([s1])
self.assertTrue(s1 is not s2)
- self.assertTrue(type(s2) is bytearray, type(s2))
+ self.assertTrue(type(s2) is self.type2test, type(s2))
# Test reverse, calling join on subclass
s3 = s1.join([b"abcd"])
- self.assertTrue(type(s3) is bytearray)
+ self.assertTrue(type(s3) is self.type2test)
def test_pickle(self):
- a = ByteArraySubclass(b"abcd")
+ a = self.subclass2test(b"abcd")
a.x = 10
- a.y = ByteArraySubclass(b"efgh")
+ a.y = self.subclass2test(b"efgh")
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
b = pickle.loads(pickle.dumps(a, proto))
self.assertNotEqual(id(a), id(b))
@@ -1052,9 +1067,9 @@
self.assertEqual(type(a.y), type(b.y))
def test_copy(self):
- a = ByteArraySubclass(b"abcd")
+ a = self.subclass2test(b"abcd")
a.x = 10
- a.y = ByteArraySubclass(b"efgh")
+ a.y = self.subclass2test(b"efgh")
for copy_method in (copy.copy, copy.deepcopy):
b = copy_method(a)
self.assertNotEqual(id(a), id(b))
@@ -1064,21 +1079,38 @@
self.assertEqual(type(a), type(b))
self.assertEqual(type(a.y), type(b.y))
+
+class ByteArraySubclass(bytearray):
+ pass
+
+class BytesSubclass(bytes):
+ pass
+
+class ByteArraySubclassTest(SubclassTest):
+ type2test = bytearray
+ subclass2test = ByteArraySubclass
+
def test_init_override(self):
class subclass(bytearray):
- def __init__(self, newarg=1, *args, **kwargs):
- bytearray.__init__(self, *args, **kwargs)
+ def __init__(me, newarg=1, *args, **kwargs):
+ bytearray.__init__(me, *args, **kwargs)
+ x = subclass(4, b"abcd")
x = subclass(4, source=b"abcd")
self.assertEqual(x, b"abcd")
x = subclass(newarg=4, source=b"abcd")
self.assertEqual(x, b"abcd")
+class BytesSubclassTest(SubclassTest):
+ type2test = bytes
+ subclass2test = BytesSubclass
+
+
def test_main():
test.support.run_unittest(
BytesTest, AssortedBytesTest, BytesAsStringTest,
- ByteArrayTest, ByteArrayAsStringTest, ByteArraySubclassTest,
- BytearrayPEP3137Test)
+ ByteArrayTest, ByteArrayAsStringTest, BytesSubclassTest,
+ ByteArraySubclassTest, BytearrayPEP3137Test)
if __name__ == "__main__":
test_main()
Modified: python/branches/py3k-cdecimal/Lib/test/test_cgi.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_cgi.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_cgi.py Thu Jan 21 20:32:23 2010
@@ -143,7 +143,7 @@
# test individual fields
for key in expect.keys():
expect_val = expect[key]
- self.assertTrue(key in fs)
+ self.assertIn(key, fs)
if len(expect_val) > 1:
self.assertEqual(fs.getvalue(key), expect_val)
else:
Modified: python/branches/py3k-cdecimal/Lib/test/test_cmd.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_cmd.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_cmd.py Thu Jan 21 20:32:23 2010
@@ -60,15 +60,17 @@
>>> mycmd.completenames("12")
[]
>>> mycmd.completenames("help")
- ['help', 'help']
+ ['help']
Test for the function complete_help():
>>> mycmd.complete_help("a")
['add']
>>> mycmd.complete_help("he")
- ['help', 'help']
+ ['help']
>>> mycmd.complete_help("12")
[]
+ >>> sorted(mycmd.complete_help(""))
+ ['add', 'exit', 'help', 'shell']
Test for the function do_help():
>>> mycmd.do_help("testet")
@@ -144,7 +146,7 @@
def complete_command(self):
print("complete command")
- def do_shell(self):
+ def do_shell(self, s):
pass
def do_add(self, s):
@@ -171,6 +173,7 @@
support.run_doctest(test_cmd, verbose)
def test_coverage(coverdir):
+ import trace
tracer=trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix,],
trace=0, count=1)
tracer.run('reload(cmd);test_main()')
@@ -181,5 +184,7 @@
if __name__ == "__main__":
if "-c" in sys.argv:
test_coverage('/tmp/cmd.cover')
+ elif "-i" in sys.argv:
+ samplecmdclass().cmdloop()
else:
test_main()
Modified: python/branches/py3k-cdecimal/Lib/test/test_cmd_line.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_cmd_line.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_cmd_line.py Thu Jan 21 20:32:23 2010
@@ -49,7 +49,7 @@
def verify_valid_flag(self, cmd_line):
data = self.start_python(cmd_line)
self.assertTrue(data == b'' or data.endswith(b'\n'))
- self.assertTrue(b'Traceback' not in data)
+ self.assertNotIn(b'Traceback', data)
def test_optimize(self):
self.verify_valid_flag('-O')
@@ -65,7 +65,7 @@
self.verify_valid_flag('-S')
def test_usage(self):
- self.assertTrue(b'usage' in self.start_python('-h'))
+ self.assertIn(b'usage', self.start_python('-h'))
def test_version(self):
version = ('Python %d.%d' % sys.version_info[:2]).encode("ascii")
@@ -77,10 +77,10 @@
# codec), a recursion loop can occur.
data, rc = self.start_python_and_exit_code('-v')
self.assertEqual(rc, 0)
- self.assertTrue(b'stack overflow' not in data)
+ self.assertNotIn(b'stack overflow', data)
data, rc = self.start_python_and_exit_code('-vv')
self.assertEqual(rc, 0)
- self.assertTrue(b'stack overflow' not in data)
+ self.assertNotIn(b'stack overflow', data)
def test_run_module(self):
# Test expected operation of the '-m' switch
@@ -166,8 +166,8 @@
p = _spawn_python_with_env('-S', '-c',
'import sys; print(sys.path)')
stdout, _ = p.communicate()
- self.assertTrue(path1.encode('ascii') in stdout)
- self.assertTrue(path2.encode('ascii') in stdout)
+ self.assertIn(path1.encode('ascii'), stdout)
+ self.assertIn(path2.encode('ascii'), stdout)
def test_main():
Modified: python/branches/py3k-cdecimal/Lib/test/test_cmd_line_script.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_cmd_line_script.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_cmd_line_script.py Thu Jan 21 20:32:23 2010
@@ -80,9 +80,9 @@
print(printed_file)
print(printed_package)
print(printed_argv0)
- self.assertTrue(printed_file.encode('utf-8') in data)
- self.assertTrue(printed_package.encode('utf-8') in data)
- self.assertTrue(printed_argv0.encode('utf-8') in data)
+ self.assertIn(printed_file.encode('utf-8'), data)
+ self.assertIn(printed_package.encode('utf-8'), data)
+ self.assertIn(printed_argv0.encode('utf-8'), data)
def _check_import_error(self, script_name, expected_msg,
*cmd_line_switches):
@@ -92,7 +92,7 @@
print('Output from test script %r:' % script_name)
print(data)
print('Expected output: %r' % expected_msg)
- self.assertTrue(expected_msg.encode('utf-8') in data)
+ self.assertIn(expected_msg.encode('utf-8'), data)
def test_basic_script(self):
with temp_dir() as script_dir:
Modified: python/branches/py3k-cdecimal/Lib/test/test_collections.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_collections.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_collections.py Thu Jan 21 20:32:23 2010
@@ -44,9 +44,9 @@
namedtuple('_', 'a b c') # Test leading underscores in a typename
nt = namedtuple('nt', 'the quick brown fox') # check unicode input
- self.assertTrue("u'" not in repr(nt._fields))
+ self.assertNotIn("u'", repr(nt._fields))
nt = namedtuple('nt', ('the', 'quick')) # check unicode input
- self.assertTrue("u'" not in repr(nt._fields))
+ self.assertNotIn("u'", repr(nt._fields))
self.assertRaises(TypeError, Point._make, [11]) # catch too few args
self.assertRaises(TypeError, Point._make, [11, 22, 33]) # catch too many args
@@ -75,8 +75,8 @@
self.assertRaises(TypeError, eval, 'Point(XXX=1, y=2)', locals()) # wrong keyword argument
self.assertRaises(TypeError, eval, 'Point(x=1)', locals()) # missing keyword argument
self.assertEqual(repr(p), 'Point(x=11, y=22)')
- self.assertTrue('__dict__' not in dir(p)) # verify instance has no dict
- self.assertTrue('__weakref__' not in dir(p))
+ self.assertNotIn('__dict__', dir(p)) # verify instance has no dict
+ self.assertNotIn('__weakref__', dir(p))
self.assertEqual(p, Point._make([11, 22])) # test _make classmethod
self.assertEqual(p._fields, ('x', 'y')) # test _fields attribute
self.assertEqual(p._replace(x=1), (1, 22)) # test _replace method
@@ -598,6 +598,7 @@
c = Counter(a=10, b=-2, c=0)
for elem in c:
self.assertTrue(elem in c)
+ self.assertIn(elem, c)
def test_multiset_operations(self):
# Verify that adding a zero counter will strip zeros and negatives
@@ -697,7 +698,7 @@
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
od = OrderedDict(pairs)
del od['a']
- self.assertTrue('a' not in od)
+ self.assertNotIn('a', od)
with self.assertRaises(KeyError):
del od['a']
self.assertEqual(list(od.items()), pairs[:2] + pairs[3:])
Modified: python/branches/py3k-cdecimal/Lib/test/test_compile.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_compile.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_compile.py Thu Jan 21 20:32:23 2010
@@ -389,10 +389,10 @@
import __mangled_mod
import __package__.module
- self.assertTrue("_A__mangled" in A.f.__code__.co_varnames)
- self.assertTrue("__not_mangled__" in A.f.__code__.co_varnames)
- self.assertTrue("_A__mangled_mod" in A.f.__code__.co_varnames)
- self.assertTrue("__package__" in A.f.__code__.co_varnames)
+ self.assertIn("_A__mangled", A.f.__code__.co_varnames)
+ self.assertIn("__not_mangled__", A.f.__code__.co_varnames)
+ self.assertIn("_A__mangled_mod", A.f.__code__.co_varnames)
+ self.assertIn("__package__", A.f.__code__.co_varnames)
def test_compile_ast(self):
fname = __file__
Modified: python/branches/py3k-cdecimal/Lib/test/test_contains.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_contains.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_contains.py Thu Jan 21 20:32:23 2010
@@ -20,19 +20,19 @@
a = base_set(1)
b = myset(1)
c = seq(1)
- self.assertTrue(1 in b)
- self.assertTrue(0 not in b)
- self.assertTrue(1 in c)
- self.assertTrue(0 not in c)
+ self.assertIn(1, b)
+ self.assertNotIn(0, b)
+ self.assertIn(1, c)
+ self.assertNotIn(0, c)
self.assertRaises(TypeError, lambda: 1 in a)
self.assertRaises(TypeError, lambda: 1 not in a)
# test char in string
- self.assertTrue('c' in 'abc')
- self.assertTrue('d' not in 'abc')
+ self.assertIn('c', 'abc')
+ self.assertNotIn('d', 'abc')
- self.assertTrue('' in '')
- self.assertTrue('' in 'abc')
+ self.assertIn('', '')
+ self.assertIn('', 'abc')
self.assertRaises(TypeError, lambda: None in 'abc')
@@ -40,15 +40,15 @@
# a collection of tests on builtin sequence types
a = range(10)
for i in a:
- self.assertTrue(i in a)
- self.assertTrue(16 not in a)
- self.assertTrue(a not in a)
+ self.assertIn(i, a)
+ self.assertNotIn(16, a)
+ self.assertNotIn(a, a)
a = tuple(a)
for i in a:
- self.assertTrue(i in a)
- self.assertTrue(16 not in a)
- self.assertTrue(a not in a)
+ self.assertIn(i, a)
+ self.assertNotIn(16, a)
+ self.assertNotIn(a, a)
class Deviant1:
"""Behaves strangely when compared
@@ -64,7 +64,7 @@
self.aList.remove(14)
return 0
- self.assertTrue(Deviant1() not in Deviant1.aList)
+ self.assertNotIn(Deviant1(), Deviant1.aList)
def test_nonreflexive(self):
# containment and equality tests involving elements that are
@@ -81,7 +81,7 @@
for constructor in constructors:
container = constructor(values)
for elem in container:
- self.assertTrue(elem in container)
+ self.assertIn(elem, container)
self.assertTrue(container == constructor(values))
self.assertTrue(container == container)
Modified: python/branches/py3k-cdecimal/Lib/test/test_copyreg.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_copyreg.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_copyreg.py Thu Jan 21 20:32:23 2010
@@ -54,7 +54,7 @@
self.assertTrue(copyreg._extension_registry[mod, func] == code)
self.assertTrue(copyreg._inverted_registry[code] == (mod, func))
# Shouldn't be in the cache.
- self.assertTrue(code not in copyreg._extension_cache)
+ self.assertNotIn(code, copyreg._extension_cache)
# Redundant registration should be OK.
copyreg.add_extension(mod, func, code) # shouldn't blow up
# Conflicting code.
@@ -81,7 +81,7 @@
e.restore()
# Shouldn't be there anymore.
- self.assertTrue((mod, func) not in copyreg._extension_registry)
+ self.assertNotIn((mod, func), copyreg._extension_registry)
# The code *may* be in copyreg._extension_registry, though, if
# we happened to pick on a registered code. So don't check for
# that.
Modified: python/branches/py3k-cdecimal/Lib/test/test_csv.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_csv.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_csv.py Thu Jan 21 20:32:23 2010
@@ -811,7 +811,7 @@
# given that all three lines in sample3 are equal,
# I think that any character could have been 'guessed' as the
# delimiter, depending on dictionary order
- self.assertTrue(dialect.delimiter in self.sample3)
+ self.assertIn(dialect.delimiter, self.sample3)
dialect = sniffer.sniff(self.sample3, delimiters="?,")
self.assertEqual(dialect.delimiter, "?")
dialect = sniffer.sniff(self.sample3, delimiters="/,")
Modified: python/branches/py3k-cdecimal/Lib/test/test_datetime.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_datetime.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_datetime.py Thu Jan 21 20:32:23 2010
@@ -139,10 +139,10 @@
self.assertFalse(() == me)
self.assertTrue(() != me)
- self.assertTrue(me in [1, 20, [], me])
+ self.assertIn(me, [1, 20, [], me])
self.assertFalse(me not in [1, 20, [], me])
- self.assertTrue([] in [me, 1, 20, []])
+ self.assertIn([], [me, 1, 20, []])
self.assertFalse([] not in [me, 1, 20, []])
def test_harmful_mixed_comparison(self):
Modified: python/branches/py3k-cdecimal/Lib/test/test_dbm.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_dbm.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_dbm.py Thu Jan 21 20:32:23 2010
@@ -131,7 +131,7 @@
f = module.open(_fname, 'w')
f[b"1"] = b"1"
# and test that we can find it
- self.assertTrue(b"1" in f)
+ self.assertIn(b"1", f)
# and read it
self.assertTrue(f[b"1"] == b"1")
f.close()
@@ -154,9 +154,9 @@
self.d[k] = v
self.assertEqual(sorted(self.d.keys()), sorted(k for (k, v) in a))
for k, v in a:
- self.assertTrue(k in self.d)
+ self.assertIn(k, self.d)
self.assertEqual(self.d[k], v)
- self.assertTrue(b'xxx' not in self.d)
+ self.assertNotIn(b'xxx', self.d)
self.assertRaises(KeyError, lambda: self.d[b'xxx'])
self.d.close()
Modified: python/branches/py3k-cdecimal/Lib/test/test_dbm_dumb.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_dbm_dumb.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_dbm_dumb.py Thu Jan 21 20:32:23 2010
@@ -93,7 +93,7 @@
def test_write_contains(self):
f = dumbdbm.open(_fname)
f[b'1'] = b'hello'
- self.assertTrue(b'1' in f)
+ self.assertIn(b'1', f)
f.close()
def test_write_write_read(self):
@@ -118,7 +118,7 @@
f['1'] = 'a'
f.close()
f = dumbdbm.open(_fname, 'r')
- self.assertTrue('\u00fc' in f)
+ self.assertIn('\u00fc', f)
self.assertEqual(f['\u00fc'.encode('utf-8')],
self._dict['\u00fc'.encode('utf-8')])
self.assertEqual(f[b'1'], b'a')
Modified: python/branches/py3k-cdecimal/Lib/test/test_dbm_gnu.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_dbm_gnu.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_dbm_gnu.py Thu Jan 21 20:32:23 2010
@@ -24,11 +24,11 @@
self.g[b'bytes'] = b'data'
key_set = set(self.g.keys())
self.assertEqual(key_set, set([b'a', b'bytes', b'12345678910']))
- self.assertTrue(b'a' in self.g)
+ self.assertIn(b'a', self.g)
self.assertEqual(self.g[b'bytes'], b'data')
key = self.g.firstkey()
while key:
- self.assertTrue(key in key_set)
+ self.assertIn(key, key_set)
key_set.remove(key)
key = self.g.nextkey(key)
self.assertRaises(KeyError, lambda: self.g['xxx'])
Modified: python/branches/py3k-cdecimal/Lib/test/test_dbm_ndbm.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_dbm_ndbm.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_dbm_ndbm.py Thu Jan 21 20:32:23 2010
@@ -24,7 +24,7 @@
self.d[b'bytes'] = b'data'
self.d['12345678910'] = '019237410982340912840198242'
self.d.keys()
- self.assertTrue(b'a' in self.d)
+ self.assertIn(b'a', self.d)
self.assertEqual(self.d[b'bytes'], b'data')
self.d.close()
Modified: python/branches/py3k-cdecimal/Lib/test/test_decimal.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_decimal.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_decimal.py Thu Jan 21 20:32:23 2010
@@ -1673,8 +1673,8 @@
self.assertEqual(v1, v2)
def test_equality_with_other_types(self):
- self.assertTrue(Decimal(10) in ['a', 1.0, Decimal(10), (1,2), {}])
- self.assertTrue(Decimal(10) not in ['a', 1.0, (1,2), {}])
+ self.assertIn(Decimal(10), ['a', 1.0, Decimal(10), (1,2), {}])
+ self.assertNotIn(Decimal(10), ['a', 1.0, (1,2), {}])
def test_copy(self):
# All copies should be deep
Modified: python/branches/py3k-cdecimal/Lib/test/test_defaultdict.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_defaultdict.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_defaultdict.py Thu Jan 21 20:32:23 2010
@@ -32,14 +32,14 @@
self.assertEqual(d2["foo"], 1)
self.assertEqual(d2["bar"], 2)
self.assertEqual(d2[42], [])
- self.assertTrue("foo" in d2)
- self.assertTrue("foo" in d2.keys())
- self.assertTrue("bar" in d2)
- self.assertTrue("bar" in d2.keys())
- self.assertTrue(42 in d2)
- self.assertTrue(42 in d2.keys())
- self.assertTrue(12 not in d2)
- self.assertTrue(12 not in d2.keys())
+ self.assertIn("foo", d2)
+ self.assertIn("foo", d2.keys())
+ self.assertIn("bar", d2)
+ self.assertIn("bar", d2.keys())
+ self.assertIn(42, d2)
+ self.assertIn(42, d2.keys())
+ self.assertNotIn(12, d2)
+ self.assertNotIn(12, d2.keys())
d2.default_factory = None
self.assertEqual(d2.default_factory, None)
try:
Modified: python/branches/py3k-cdecimal/Lib/test/test_deque.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_deque.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_deque.py Thu Jan 21 20:32:23 2010
@@ -199,9 +199,9 @@
self.assertEqual(len(d), n-i)
j = random.randrange(-len(d), len(d))
val = d[j]
- self.assertTrue(val in d)
+ self.assertIn(val, d)
del d[j]
- self.assertTrue(val not in d)
+ self.assertNotIn(val, d)
self.assertEqual(len(d), 0)
def test_reverse(self):
@@ -328,7 +328,7 @@
e = eval(repr(d))
self.assertEqual(list(d), list(e))
d.append(d)
- self.assertTrue('...' in repr(d))
+ self.assertIn('...', repr(d))
def test_print(self):
d = deque(range(200))
Modified: python/branches/py3k-cdecimal/Lib/test/test_descr.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_descr.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_descr.py Thu Jan 21 20:32:23 2010
@@ -500,7 +500,7 @@
return 42
self.assertEqual(C.name, 'C')
self.assertEqual(C.bases, ())
- self.assertTrue('spam' in C.dict)
+ self.assertIn('spam', C.dict)
c = C()
self.assertEqual(c.spam(), 42)
@@ -1651,9 +1651,9 @@
# depending on whether this test is run standalone or from a framework.
self.assertTrue(str(c1).find('C object at ') >= 0)
self.assertEqual(str(c1), repr(c1))
- self.assertTrue(-1 not in c1)
+ self.assertNotIn(-1, c1)
for i in range(10):
- self.assertTrue(i in c1)
+ self.assertIn(i, c1)
self.assertFalse(10 in c1)
# Test the default behavior for dynamic classes
class D(object):
@@ -1674,9 +1674,9 @@
# depending on whether this test is run standalone or from a framework.
self.assertTrue(str(d1).find('D object at ') >= 0)
self.assertEqual(str(d1), repr(d1))
- self.assertTrue(-1 not in d1)
+ self.assertNotIn(-1, d1)
for i in range(10):
- self.assertTrue(i in d1)
+ self.assertIn(i, d1)
self.assertFalse(10 in d1)
# Test overridden behavior
class Proxy(object):
@@ -1723,7 +1723,7 @@
p10 = Proxy(range(10))
self.assertFalse(-1 in p10)
for i in range(10):
- self.assertTrue(i in p10)
+ self.assertIn(i, p10)
self.assertFalse(10 in p10)
def test_weakrefs(self):
@@ -1784,10 +1784,10 @@
self.assertTrue(isinstance(raw, property))
attrs = dir(raw)
- self.assertTrue("__doc__" in attrs)
- self.assertTrue("fget" in attrs)
- self.assertTrue("fset" in attrs)
- self.assertTrue("fdel" in attrs)
+ self.assertIn("__doc__", attrs)
+ self.assertIn("fget", attrs)
+ self.assertIn("fset", attrs)
+ self.assertIn("fdel", attrs)
self.assertEqual(raw.__doc__, "I'm the x property.")
self.assertTrue(raw.fget is C.__dict__['getx'])
@@ -2012,12 +2012,12 @@
c = C()
self.assertEqual(interesting(dir(c)), cstuff)
- ## self.assertTrue('__self__' in dir(C.Cmethod))
+ ## self.assertIn('__self__', dir(C.Cmethod))
c.cdata = 2
c.cmethod = lambda self: 0
self.assertEqual(interesting(dir(c)), cstuff + ['cdata', 'cmethod'])
- ## self.assertTrue('__self__' in dir(c.Cmethod))
+ ## self.assertIn('__self__', dir(c.Cmethod))
class A(C):
Adata = 1
@@ -2025,13 +2025,13 @@
astuff = ['Adata', 'Amethod'] + cstuff
self.assertEqual(interesting(dir(A)), astuff)
- ## self.assertTrue('__self__' in dir(A.Amethod))
+ ## self.assertIn('__self__', dir(A.Amethod))
a = A()
self.assertEqual(interesting(dir(a)), astuff)
a.adata = 42
a.amethod = lambda self: 3
self.assertEqual(interesting(dir(a)), astuff + ['adata', 'amethod'])
- ## self.assertTrue('__self__' in dir(a.Amethod))
+ ## self.assertIn('__self__', dir(a.Amethod))
# Try a module subclass.
import sys
@@ -2583,7 +2583,7 @@
self.assertEqual(d[cistr('one')], 1)
self.assertEqual(d[cistr('tWo')], 2)
self.assertEqual(d[cistr('THrEE')], 3)
- self.assertTrue(cistr('ONe') in d)
+ self.assertIn(cistr('ONe'), d)
self.assertEqual(d.get(cistr('thrEE')), 3)
def test_classic_comparisons(self):
Modified: python/branches/py3k-cdecimal/Lib/test/test_dict.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_dict.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_dict.py Thu Jan 21 20:32:23 2010
@@ -35,7 +35,9 @@
d = {'a': 1, 'b': 2}
k = d.keys()
self.assertTrue('a' in d)
+ self.assertIn('a', d)
self.assertTrue('b' in d)
+ self.assertIn('b', d)
self.assertRaises(TypeError, d.keys, None)
self.assertEqual(repr(dict(a=1).keys()), "dict_keys(['a'])")
@@ -60,10 +62,14 @@
d = {}
self.assertTrue(not ('a' in d))
self.assertTrue('a' not in d)
+ self.assertNotIn('a', d)
d = {'a': 1, 'b': 2}
self.assertTrue('a' in d)
+ self.assertIn('a', d)
self.assertTrue('b' in d)
+ self.assertIn('b', d)
self.assertTrue('c' not in d)
+ self.assertNotIn('c', d)
self.assertRaises(TypeError, d.__contains__)
@@ -519,7 +525,9 @@
self.assertEqual(d[1], 2)
self.assertEqual(d[3], 4)
self.assertTrue(2 not in d)
+ self.assertNotIn(2, d)
self.assertTrue(2 not in d.keys())
+ self.assertNotIn(2, d.keys())
self.assertEqual(d[2], 42)
class E(dict):
def __missing__(self, key):
Modified: python/branches/py3k-cdecimal/Lib/test/test_dictviews.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_dictviews.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_dictviews.py Thu Jan 21 20:32:23 2010
@@ -24,10 +24,10 @@
self.assertNotEqual(keys, {1, "b"})
self.assertNotEqual(keys, {1})
self.assertNotEqual(keys, 42)
- self.assertTrue(1 in keys)
- self.assertTrue("a" in keys)
- self.assertTrue(10 not in keys)
- self.assertTrue("Z" not in keys)
+ self.assertIn(1, keys)
+ self.assertIn("a", keys)
+ self.assertNotIn(10, keys)
+ self.assertNotIn("Z", keys)
self.assertEqual(d.keys(), d.keys())
e = {1: 11, "a": "def"}
self.assertEqual(d.keys(), e.keys())
@@ -44,13 +44,13 @@
self.assertNotEqual(items, {(1, 10), ("a", "def")})
self.assertNotEqual(items, {(1, 10)})
self.assertNotEqual(items, 42)
- self.assertTrue((1, 10) in items)
- self.assertTrue(("a", "ABC") in items)
- self.assertTrue((1, 11) not in items)
- self.assertTrue(1 not in items)
- self.assertTrue(() not in items)
- self.assertTrue((1,) not in items)
- self.assertTrue((1, 2, 3) not in items)
+ self.assertIn((1, 10), items)
+ self.assertIn(("a", "ABC"), items)
+ self.assertNotIn((1, 11), items)
+ self.assertNotIn(1, items)
+ self.assertNotIn((), items)
+ self.assertNotIn((1,), items)
+ self.assertNotIn((1, 2, 3), items)
self.assertEqual(d.items(), d.items())
e = d.copy()
self.assertEqual(d.items(), e.items())
Modified: python/branches/py3k-cdecimal/Lib/test/test_exceptions.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_exceptions.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_exceptions.py Thu Jan 21 20:32:23 2010
@@ -337,7 +337,7 @@
try:
Exception().__traceback__ = 5
except TypeError as e:
- self.assertTrue("__traceback__ must be a traceback" in str(e))
+ self.assertIn("__traceback__ must be a traceback", str(e))
else:
self.fail("No exception raised")
@@ -597,7 +597,7 @@
return sys.exc_info()
e, v, tb = g()
self.assertTrue(isinstance(v, RuntimeError), type(v))
- self.assertTrue("maximum recursion depth exceeded" in str(v), str(v))
+ self.assertIn("maximum recursion depth exceeded", str(v))
def test_MemoryError(self):
Modified: python/branches/py3k-cdecimal/Lib/test/test_float.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_float.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_float.py Thu Jan 21 20:32:23 2010
@@ -7,6 +7,7 @@
from math import isinf, isnan, copysign, ldexp
import operator
import random, fractions
+import re
INF = float("inf")
NAN = float("nan")
@@ -20,6 +21,74 @@
test_dir = os.path.dirname(__file__) or os.curdir
format_testfile = os.path.join(test_dir, 'formatfloat_testcases.txt')
+finite_decimal_parser = re.compile(r""" # A numeric string consists of:
+ (?P<sign>[-+])? # an optional sign, followed by
+ (?=\d|\.\d) # a number with at least one digit
+ (?P<int>\d*) # having a (possibly empty) integer part
+ (?:\.(?P<frac>\d*))? # followed by an optional fractional part
+ (?:E(?P<exp>[-+]?\d+))? # and an optional exponent
+ \Z
+""", re.VERBOSE | re.IGNORECASE | re.UNICODE).match
+
+# Pure Python version of correctly rounded string->float conversion.
+# Avoids any use of floating-point by returning the result as a hex string.
+def strtod(s, mant_dig=53, min_exp = -1021, max_exp = 1024):
+ """Convert a finite decimal string to a hex string representing an
+ IEEE 754 binary64 float. Return 'inf' or '-inf' on overflow.
+ This function makes no use of floating-point arithmetic at any
+ stage."""
+
+ # parse string into a pair of integers 'a' and 'b' such that
+ # abs(decimal value) = a/b, and a boolean 'negative'.
+ m = finite_decimal_parser(s)
+ if m is None:
+ raise ValueError('invalid numeric string')
+ fraction = m.group('frac') or ''
+ intpart = int(m.group('int') + fraction)
+ exp = int(m.group('exp') or '0') - len(fraction)
+ negative = m.group('sign') == '-'
+ a, b = intpart*10**max(exp, 0), 10**max(0, -exp)
+
+ # quick return for zeros
+ if not a:
+ return '-0x0.0p+0' if negative else '0x0.0p+0'
+
+ # compute exponent e for result; may be one too small in the case
+ # that the rounded value of a/b lies in a different binade from a/b
+ d = a.bit_length() - b.bit_length()
+ d += (a >> d if d >= 0 else a << -d) >= b
+ e = max(d, min_exp) - mant_dig
+
+ # approximate a/b by number of the form q * 2**e; adjust e if necessary
+ a, b = a << max(-e, 0), b << max(e, 0)
+ q, r = divmod(a, b)
+ if 2*r > b or 2*r == b and q & 1:
+ q += 1
+ if q.bit_length() == mant_dig+1:
+ q //= 2
+ e += 1
+
+ # double check that (q, e) has the right form
+ assert q.bit_length() <= mant_dig and e >= min_exp - mant_dig
+ assert q.bit_length() == mant_dig or e == min_exp - mant_dig
+
+ # check for overflow and underflow
+ if e + q.bit_length() > max_exp:
+ return '-inf' if negative else 'inf'
+ if not q:
+ return '-0x0.0p+0' if negative else '0x0.0p+0'
+
+ # for hex representation, shift so # bits after point is a multiple of 4
+ hexdigs = 1 + (mant_dig-2)//4
+ shift = 3 - (mant_dig-2)%4
+ q, e = q << shift, e - shift
+ return '{}0x{:x}.{:0{}x}p{:+d}'.format(
+ '-' if negative else '',
+ q // 16**hexdigs,
+ q % 16**hexdigs,
+ hexdigs,
+ e + 4*hexdigs)
+
class GeneralFloatCases(unittest.TestCase):
def test_float(self):
@@ -144,11 +213,16 @@
def test_float_containment(self):
floats = (INF, -INF, 0.0, 1.0, NAN)
for f in floats:
+ self.assertIn(f, [f])
self.assertTrue(f in [f], "'%r' not in []" % f)
+ self.assertIn(f, (f,))
self.assertTrue(f in (f,), "'%r' not in ()" % f)
+ self.assertIn(f, {f})
self.assertTrue(f in {f}, "'%r' not in set()" % f)
+ self.assertIn(f, {f: None})
self.assertTrue(f in {f: None}, "'%r' not in {}" % f)
self.assertEqual([f].count(f), 1, "[].count('%r') != 1" % f)
+ self.assertIn(f, floats)
self.assertTrue(f in floats, "'%r' not in container" % f)
for f in floats:
@@ -1263,6 +1337,38 @@
else:
self.identical(x, fromHex(toHex(x)))
+class StrtodTestCase(unittest.TestCase):
+ def check_string(self, s):
+ expected = strtod(s)
+ try:
+ fs = float(s)
+ except OverflowError:
+ got = '-inf' if s[0] == '-' else 'inf'
+ else:
+ got = fs.hex()
+ self.assertEqual(expected, got,
+ "Incorrectly rounded str->float conversion for "
+ "{}: expected {}, got {}".format(s, expected, got))
+
+ @unittest.skipUnless(getattr(sys, 'float_repr_style', '') == 'short',
+ "applies only when using short float repr style")
+ def test_bug7632(self):
+ # check a few particular values that gave incorrectly rounded
+ # results with previous versions of dtoa.c
+ test_strings = [
+ '94393431193180696942841837085033647913224148539854e-358',
+ '12579816049008305546974391768996369464963024663104e-357',
+ '17489628565202117263145367596028389348922981857013e-357',
+ '18487398785991994634182916638542680759613590482273e-357',
+ '32002864200581033134358724675198044527469366773928e-358',
+ '73608278998966969345824653500136787876436005957953e-358',
+ '64774478836417299491718435234611299336288082136054e-358',
+ '13704940134126574534878641876947980878824688451169e-357',
+ '46697445774047060960624497964425416610480524760471e-358',
+ ]
+ for s in test_strings:
+ self.check_string(s)
+
def test_main():
support.run_unittest(
@@ -1275,6 +1381,7 @@
RoundTestCase,
InfNanTest,
HexFloatTestCase,
+ StrtodTestCase,
)
if __name__ == '__main__':
Modified: python/branches/py3k-cdecimal/Lib/test/test_funcattrs.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_funcattrs.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_funcattrs.py Thu Jan 21 20:32:23 2010
@@ -35,11 +35,11 @@
def test_dir_includes_correct_attrs(self):
self.b.known_attr = 7
- self.assertTrue('known_attr' in dir(self.b),
+ self.assertIn('known_attr', dir(self.b),
"set attributes not in dir listing of method")
# Test on underlying function object of method
self.F.a.known_attr = 7
- self.assertTrue('known_attr' in dir(self.fi.a), "set attribute on function "
+ self.assertIn('known_attr', dir(self.fi.a), "set attribute on function "
"implementations, should show up in next dir")
def test_duplicate_function_equality(self):
Modified: python/branches/py3k-cdecimal/Lib/test/test_glob.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_glob.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_glob.py Thu Jan 21 20:32:23 2010
@@ -96,7 +96,7 @@
res = glob.glob(self.tempdir + '*' + os.sep)
self.assertEqual(len(res), 1)
# either of these results are reasonable
- self.assertTrue(res[0] in [self.tempdir, self.tempdir + os.sep])
+ self.assertIn(res[0], [self.tempdir, self.tempdir + os.sep])
def test_glob_broken_symlinks(self):
if hasattr(os, 'symlink'):
Modified: python/branches/py3k-cdecimal/Lib/test/test_gzip.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_gzip.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_gzip.py Thu Jan 21 20:32:23 2010
@@ -253,6 +253,18 @@
else:
self.fail("1/0 didn't raise an exception")
+ def test_zero_padded_file(self):
+ with gzip.GzipFile(self.filename, "wb") as f:
+ f.write(data1 * 50)
+
+ # Pad the file with zeroes
+ with open(self.filename, "ab") as f:
+ f.write(b"\x00" * 50)
+
+ with gzip.GzipFile(self.filename, "rb") as f:
+ d = f.read()
+ self.assertEqual(d, data1 * 50, "Incorrect data in file")
+
def test_main(verbose=None):
support.run_unittest(TestGzip)
Modified: python/branches/py3k-cdecimal/Lib/test/test_hashlib.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_hashlib.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_hashlib.py Thu Jan 21 20:32:23 2010
@@ -2,12 +2,14 @@
#
# $Id$
#
-# Copyright (C) 2005-2009 Gregory P. Smith (greg at krypto.org)
+# Copyright (C) 2005-2010 Gregory P. Smith (greg at krypto.org)
# Licensed to PSF under a Contributor Agreement.
#
+import array
import hashlib
from io import StringIO
+import itertools
import sys
try:
import threading
@@ -93,6 +95,13 @@
super(HashLibTestCase, self).__init__(*args, **kwargs)
+ def test_hash_array(self):
+ a = array.array("b", range(10))
+ constructors = self.constructors_to_test.values()
+ for cons in itertools.chain.from_iterable(constructors):
+ c = cons(a)
+ c.hexdigest()
+
def test_unknown_hash(self):
try:
hashlib.new('spam spam spam spam spam')
Modified: python/branches/py3k-cdecimal/Lib/test/test_http_cookiejar.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_http_cookiejar.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_http_cookiejar.py Thu Jan 21 20:32:23 2010
@@ -441,8 +441,8 @@
interact_netscape(c, "http://www.acme.com/", 'version=eggs; spam=eggs')
cookies = c._cookies["www.acme.com"]["/"]
- self.assertTrue('expires' in cookies)
- self.assertTrue('version' in cookies)
+ self.assertIn('expires', cookies)
+ self.assertIn('version', cookies)
def test_expires(self):
# if expires is in future, keep cookie...
@@ -457,7 +457,8 @@
now)
h = interact_netscape(c, "http://www.acme.com/")
self.assertEquals(len(c), 1)
- self.assertTrue('spam="bar"' in h and "foo" not in h)
+ self.assertIn('spam="bar"', h)
+ self.assertNotIn("foo", h)
# max-age takes precedence over expires, and zero max-age is request to
# delete both new cookie and any old matching cookie
@@ -478,7 +479,7 @@
self.assertEquals(len(c), 2)
c.clear_session_cookies()
self.assertEquals(len(c), 1)
- self.assertTrue('spam="bar"' in h)
+ self.assertIn('spam="bar"', h)
# XXX RFC 2965 expiry rules (some apply to V0 too)
@@ -488,39 +489,39 @@
c = CookieJar(pol)
interact_2965(c, "http://www.acme.com/", 'spam="bar"; Version="1"')
- self.assertTrue("/" in c._cookies["www.acme.com"])
+ self.assertIn("/", c._cookies["www.acme.com"])
c = CookieJar(pol)
interact_2965(c, "http://www.acme.com/blah", 'eggs="bar"; Version="1"')
- self.assertTrue("/" in c._cookies["www.acme.com"])
+ self.assertIn("/", c._cookies["www.acme.com"])
c = CookieJar(pol)
interact_2965(c, "http://www.acme.com/blah/rhubarb",
'eggs="bar"; Version="1"')
- self.assertTrue("/blah/" in c._cookies["www.acme.com"])
+ self.assertIn("/blah/", c._cookies["www.acme.com"])
c = CookieJar(pol)
interact_2965(c, "http://www.acme.com/blah/rhubarb/",
'eggs="bar"; Version="1"')
- self.assertTrue("/blah/rhubarb/" in c._cookies["www.acme.com"])
+ self.assertIn("/blah/rhubarb/", c._cookies["www.acme.com"])
# Netscape
c = CookieJar()
interact_netscape(c, "http://www.acme.com/", 'spam="bar"')
- self.assertTrue("/" in c._cookies["www.acme.com"])
+ self.assertIn("/", c._cookies["www.acme.com"])
c = CookieJar()
interact_netscape(c, "http://www.acme.com/blah", 'eggs="bar"')
- self.assertTrue("/" in c._cookies["www.acme.com"])
+ self.assertIn("/", c._cookies["www.acme.com"])
c = CookieJar()
interact_netscape(c, "http://www.acme.com/blah/rhubarb", 'eggs="bar"')
- self.assertTrue("/blah" in c._cookies["www.acme.com"])
+ self.assertIn("/blah", c._cookies["www.acme.com"])
c = CookieJar()
interact_netscape(c, "http://www.acme.com/blah/rhubarb/", 'eggs="bar"')
- self.assertTrue("/blah/rhubarb" in c._cookies["www.acme.com"])
+ self.assertIn("/blah/rhubarb", c._cookies["www.acme.com"])
def test_escape_path(self):
cases = [
@@ -877,21 +878,21 @@
url = "http://foo.bar.com/"
interact_2965(c, url, "spam=eggs; Version=1")
h = interact_2965(c, url)
- self.assertTrue("Domain" not in h,
+ self.assertNotIn("Domain", h,
"absent domain returned with domain present")
c = CookieJar(pol)
url = "http://foo.bar.com/"
interact_2965(c, url, 'spam=eggs; Version=1; Domain=.bar.com')
h = interact_2965(c, url)
- self.assertTrue('$Domain=".bar.com"' in h, "domain not returned")
+ self.assertIn('$Domain=".bar.com"', h, "domain not returned")
c = CookieJar(pol)
url = "http://foo.bar.com/"
# note missing initial dot in Domain
interact_2965(c, url, 'spam=eggs; Version=1; Domain=bar.com')
h = interact_2965(c, url)
- self.assertTrue('$Domain="bar.com"' in h, "domain not returned")
+ self.assertIn('$Domain="bar.com"', h, "domain not returned")
def test_path_mirror(self):
pol = DefaultCookiePolicy(rfc2965=True)
@@ -907,7 +908,7 @@
url = "http://foo.bar.com/"
interact_2965(c, url, 'spam=eggs; Version=1; Path=/')
h = interact_2965(c, url)
- self.assertTrue('$Path="/"' in h, "path not returned")
+ self.assertIn('$Path="/"', h, "path not returned")
def test_port_mirror(self):
pol = DefaultCookiePolicy(rfc2965=True)
@@ -1449,7 +1450,8 @@
c, "http://www.acme.com/foo%2f%25/<<%0anew\345/\346\370\345",
'bar=baz; path="/foo/"; version=1');
version_re = re.compile(r'^\$version=\"?1\"?', re.I)
- self.assertTrue("foo=bar" in cookie and version_re.search(cookie))
+ self.assertIn("foo=bar", cookie)
+ self.assertTrue(version_re.search(cookie))
cookie = interact_2965(
c, "http://www.acme.com/foo/%25/<<%0anew\345/\346\370\345")
@@ -1493,11 +1495,11 @@
new_c = save_and_restore(c, True)
self.assertEquals(len(new_c), 6) # none discarded
- self.assertTrue("name='foo1', value='bar'" in repr(new_c))
+ self.assertIn("name='foo1', value='bar'", repr(new_c))
new_c = save_and_restore(c, False)
self.assertEquals(len(new_c), 4) # 2 of them discarded on save
- self.assertTrue("name='foo1', value='bar'" in repr(new_c))
+ self.assertIn("name='foo1', value='bar'", repr(new_c))
def test_netscape_misc(self):
# Some additional Netscape cookies tests.
@@ -1519,9 +1521,8 @@
req = urllib.request.Request("http://foo.bar.acme.com/foo")
c.add_cookie_header(req)
- self.assertTrue(
- "PART_NUMBER=3,4" in req.get_header("Cookie") and
- "Customer=WILE_E_COYOTE" in req.get_header("Cookie"))
+ self.assertIn("PART_NUMBER=3,4", req.get_header("Cookie"))
+ self.assertIn("Customer=WILE_E_COYOTE",req.get_header("Cookie"))
def test_intranet_domains_2965(self):
# Test handling of local intranet hostnames without a dot.
@@ -1530,11 +1531,12 @@
"foo1=bar; PORT; Discard; Version=1;")
cookie = interact_2965(c, "http://example/",
'foo2=bar; domain=".local"; Version=1')
- self.assertTrue("foo1=bar" in cookie)
+ self.assertIn("foo1=bar", cookie)
interact_2965(c, "http://example/", 'foo3=bar; Version=1')
cookie = interact_2965(c, "http://example/")
- self.assertTrue("foo2=bar" in cookie and len(c) == 3)
+ self.assertIn("foo2=bar", cookie)
+ self.assertEquals(len(c), 3)
def test_intranet_domains_ns(self):
c = CookieJar(DefaultCookiePolicy(rfc2965 = False))
@@ -1542,10 +1544,10 @@
cookie = interact_netscape(c, "http://example/",
'foo2=bar; domain=.local')
self.assertEquals(len(c), 2)
- self.assertTrue("foo1=bar" in cookie)
+ self.assertIn("foo1=bar", cookie)
cookie = interact_netscape(c, "http://example/")
- self.assertTrue("foo2=bar" in cookie)
+ self.assertIn("foo2=bar", cookie)
self.assertEquals(len(c), 2)
def test_empty_path(self):
Modified: python/branches/py3k-cdecimal/Lib/test/test_import.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_import.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_import.py Thu Jan 21 20:32:23 2010
@@ -209,7 +209,7 @@
sys.path.insert(0, os.curdir)
try:
mod = __import__(TESTFN)
- self.assertTrue(TESTFN in sys.modules, "expected module in sys.modules")
+ self.assertIn(TESTFN, sys.modules)
self.assertEquals(mod.a, 1, "module has wrong attribute values")
self.assertEquals(mod.b, 2, "module has wrong attribute values")
@@ -253,7 +253,7 @@
del sys.modules[TESTFN]
mod = __import__(TESTFN)
ext = mod.__file__[-4:]
- self.assertTrue(ext in ('.pyc', '.pyo'), ext)
+ self.assertIn(ext, ('.pyc', '.pyo'))
finally:
sys.path.pop(0)
remove_files(TESTFN)
Modified: python/branches/py3k-cdecimal/Lib/test/test_index.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_index.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_index.py Thu Jan 21 20:32:23 2010
@@ -2,13 +2,8 @@
from test import support
import operator
maxsize = support.MAX_Py_ssize_t
-minsize = -maxsize-1
-class oldstyle:
- def __index__(self):
- return self.ind
-
-class newstyle(object):
+class newstyle:
def __index__(self):
return self.ind
@@ -16,13 +11,9 @@
def __index__(self):
return self
-class TrapLong(int):
- def __index__(self):
- return self
-
class BaseTestCase(unittest.TestCase):
def setUp(self):
- self.o = oldstyle()
+ self.o = newstyle()
self.n = newstyle()
def test_basic(self):
@@ -52,9 +43,7 @@
def test_subclasses(self):
r = list(range(10))
self.assertEqual(r[TrapInt(5):TrapInt(10)], r[5:10])
- self.assertEqual(r[TrapLong(5):TrapLong(10)], r[5:10])
self.assertEqual(slice(TrapInt()).indices(0), (0,0,1))
- self.assertEqual(slice(TrapLong(0)).indices(0), (0,0,1))
def test_error(self):
self.o.ind = 'dumb'
@@ -69,9 +58,9 @@
# This test case isn't run directly. It just defines common tests
# to the different sequence types below
def setUp(self):
- self.o = oldstyle()
+ self.o = newstyle()
self.n = newstyle()
- self.o2 = oldstyle()
+ self.o2 = newstyle()
self.n2 = newstyle()
def test_index(self):
@@ -88,6 +77,21 @@
self.assertEqual(self.seq[self.o:self.o2], self.seq[1:3])
self.assertEqual(self.seq[self.n:self.n2], self.seq[2:4])
+ def test_slice_bug7532(self):
+ seqlen = len(self.seq)
+ self.o.ind = int(seqlen * 1.5)
+ self.n.ind = seqlen + 2
+ self.assertEqual(self.seq[self.o:], self.seq[0:0])
+ self.assertEqual(self.seq[:self.o], self.seq)
+ self.assertEqual(self.seq[self.n:], self.seq[0:0])
+ self.assertEqual(self.seq[:self.n], self.seq)
+ self.o2.ind = -seqlen - 2
+ self.n2.ind = -int(seqlen * 1.5)
+ self.assertEqual(self.seq[self.o2:], self.seq)
+ self.assertEqual(self.seq[:self.o2], self.seq[0:0])
+ self.assertEqual(self.seq[self.n2:], self.seq)
+ self.assertEqual(self.seq[:self.n2], self.seq[0:0])
+
def test_repeat(self):
self.o.ind = 3
self.n.ind = 2
@@ -108,7 +112,6 @@
def test_subclasses(self):
self.assertEqual(self.seq[TrapInt()], self.seq[0])
- self.assertEqual(self.seq[TrapLong()], self.seq[0])
def test_error(self):
self.o.ind = 'dumb'
@@ -155,14 +158,52 @@
self.assertEqual(lst, [5, 6, 7, 8, 9, 11] * 3)
+class NewSeq:
+
+ def __init__(self, iterable):
+ self._list = list(iterable)
+
+ def __repr__(self):
+ return repr(self._list)
+
+ def __eq__(self, other):
+ return self._list == other
+
+ def __len__(self):
+ return len(self._list)
+
+ def __mul__(self, n):
+ return self.__class__(self._list*n)
+ __rmul__ = __mul__
+
+ def __getitem__(self, index):
+ return self._list[index]
+
+
class TupleTestCase(SeqTestCase):
seq = (0,10,20,30,40,50)
+class ByteArrayTestCase(SeqTestCase):
+ seq = bytearray(b"this is a test")
+
+class BytesTestCase(SeqTestCase):
+ seq = b"this is a test"
+
class StringTestCase(SeqTestCase):
seq = "this is a test"
-class UnicodeTestCase(SeqTestCase):
- seq = "this is a test"
+class NewSeqTestCase(SeqTestCase):
+ seq = NewSeq((0,10,20,30,40,50))
+
+
+
+class RangeTestCase(unittest.TestCase):
+
+ def test_range(self):
+ n = newstyle()
+ n.ind = 5
+ self.assertEqual(range(1, 20)[n], 6)
+ self.assertEqual(range(1, 20).__getitem__(n), 6)
class OverflowTestCase(unittest.TestCase):
@@ -176,9 +217,9 @@
self.assertEqual(self.neg.__index__(), self.neg)
def test_getitem(self):
- class GetItem(object):
+ class GetItem:
def __len__(self):
- return sys.maxsize
+ assert False, "__len__ should not be invoked"
def __getitem__(self, key):
return key
x = GetItem()
@@ -186,6 +227,8 @@
self.assertEqual(x[self.neg], self.neg)
self.assertEqual(x[self.neg:self.pos].indices(maxsize),
(0, maxsize, 1))
+ self.assertEqual(x[self.neg:self.pos:1].indices(maxsize),
+ (0, maxsize, 1))
def test_sequence_repeat(self):
self.assertRaises(OverflowError, lambda: "a" * self.pos)
@@ -197,8 +240,11 @@
BaseTestCase,
ListTestCase,
TupleTestCase,
+ BytesTestCase,
+ ByteArrayTestCase,
StringTestCase,
- UnicodeTestCase,
+ NewSeqTestCase,
+ RangeTestCase,
OverflowTestCase,
)
Modified: python/branches/py3k-cdecimal/Lib/test/test_inspect.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_inspect.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_inspect.py Thu Jan 21 20:32:23 2010
@@ -117,8 +117,8 @@
x = C()
x.a = 42
members = dict(inspect.getmembers(x))
- self.assertTrue('a' in members)
- self.assertTrue('b' not in members)
+ self.assertIn('a', members)
+ self.assertNotIn('b', members)
def test_isabstract(self):
from abc import ABCMeta, abstractmethod
@@ -471,25 +471,25 @@
datablob = '1'
attrs = attrs_wo_objs(A)
- self.assertTrue(('s', 'static method', A) in attrs, 'missing static method')
- self.assertTrue(('c', 'class method', A) in attrs, 'missing class method')
- self.assertTrue(('p', 'property', A) in attrs, 'missing property')
+ self.assertIn(('s', 'static method', A), attrs, 'missing static method')
+ self.assertIn(('c', 'class method', A), attrs, 'missing class method')
+ self.assertIn(('p', 'property', A), attrs, 'missing property')
self.assertTrue(('m', 'method', A) in attrs,
'missing plain method: %r' % attrs)
- self.assertTrue(('m1', 'method', A) in attrs, 'missing plain method')
- self.assertTrue(('datablob', 'data', A) in attrs, 'missing data')
+ self.assertIn(('m1', 'method', A), attrs, 'missing plain method')
+ self.assertIn(('datablob', 'data', A), attrs, 'missing data')
class B(A):
def m(self): pass
attrs = attrs_wo_objs(B)
- self.assertTrue(('s', 'static method', A) in attrs, 'missing static method')
- self.assertTrue(('c', 'class method', A) in attrs, 'missing class method')
- self.assertTrue(('p', 'property', A) in attrs, 'missing property')
- self.assertTrue(('m', 'method', B) in attrs, 'missing plain method')
- self.assertTrue(('m1', 'method', A) in attrs, 'missing plain method')
- self.assertTrue(('datablob', 'data', A) in attrs, 'missing data')
+ self.assertIn(('s', 'static method', A), attrs, 'missing static method')
+ self.assertIn(('c', 'class method', A), attrs, 'missing class method')
+ self.assertIn(('p', 'property', A), attrs, 'missing property')
+ self.assertIn(('m', 'method', B), attrs, 'missing plain method')
+ self.assertIn(('m1', 'method', A), attrs, 'missing plain method')
+ self.assertIn(('datablob', 'data', A), attrs, 'missing data')
class C(A):
@@ -498,24 +498,24 @@
def c(self): pass
attrs = attrs_wo_objs(C)
- self.assertTrue(('s', 'static method', A) in attrs, 'missing static method')
- self.assertTrue(('c', 'method', C) in attrs, 'missing plain method')
- self.assertTrue(('p', 'property', A) in attrs, 'missing property')
- self.assertTrue(('m', 'method', C) in attrs, 'missing plain method')
- self.assertTrue(('m1', 'method', A) in attrs, 'missing plain method')
- self.assertTrue(('datablob', 'data', A) in attrs, 'missing data')
+ self.assertIn(('s', 'static method', A), attrs, 'missing static method')
+ self.assertIn(('c', 'method', C), attrs, 'missing plain method')
+ self.assertIn(('p', 'property', A), attrs, 'missing property')
+ self.assertIn(('m', 'method', C), attrs, 'missing plain method')
+ self.assertIn(('m1', 'method', A), attrs, 'missing plain method')
+ self.assertIn(('datablob', 'data', A), attrs, 'missing data')
class D(B, C):
def m1(self): pass
attrs = attrs_wo_objs(D)
- self.assertTrue(('s', 'static method', A) in attrs, 'missing static method')
- self.assertTrue(('c', 'method', C) in attrs, 'missing plain method')
- self.assertTrue(('p', 'property', A) in attrs, 'missing property')
- self.assertTrue(('m', 'method', B) in attrs, 'missing plain method')
- self.assertTrue(('m1', 'method', D) in attrs, 'missing plain method')
- self.assertTrue(('datablob', 'data', A) in attrs, 'missing data')
+ self.assertIn(('s', 'static method', A), attrs, 'missing static method')
+ self.assertIn(('c', 'method', C), attrs, 'missing plain method')
+ self.assertIn(('p', 'property', A), attrs, 'missing property')
+ self.assertIn(('m', 'method', B), attrs, 'missing plain method')
+ self.assertIn(('m1', 'method', D), attrs, 'missing plain method')
+ self.assertIn(('datablob', 'data', A), attrs, 'missing data')
def test_main():
run_unittest(TestDecorators, TestRetrievingSourceCode, TestOneliners,
Modified: python/branches/py3k-cdecimal/Lib/test/test_ioctl.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_ioctl.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_ioctl.py Thu Jan 21 20:32:23 2010
@@ -24,7 +24,7 @@
tty = open("/dev/tty", "r")
r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ")
rpgrp = struct.unpack("i", r)[0]
- self.assertTrue(rpgrp in ids, "%s not in %s" % (rpgrp, ids))
+ self.assertIn(rpgrp, ids)
def test_ioctl_mutate(self):
import array
@@ -34,7 +34,7 @@
r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1)
rpgrp = buf[0]
self.assertEquals(r, 0)
- self.assertTrue(rpgrp in ids, "%s not in %s" % (rpgrp, ids))
+ self.assertIn(rpgrp, ids)
def test_ioctl_signed_unsigned_code_param(self):
if not pty:
Modified: python/branches/py3k-cdecimal/Lib/test/test_iter.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_iter.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_iter.py Thu Jan 21 20:32:23 2010
@@ -542,23 +542,23 @@
def test_in_and_not_in(self):
for sc5 in IteratingSequenceClass(5), SequenceClass(5):
for i in range(5):
- self.assertTrue(i in sc5)
+ self.assertIn(i, sc5)
for i in "abc", -1, 5, 42.42, (3, 4), [], {1: 1}, 3-12j, sc5:
- self.assertTrue(i not in sc5)
+ self.assertNotIn(i, sc5)
self.assertRaises(TypeError, lambda: 3 in 12)
self.assertRaises(TypeError, lambda: 3 not in map)
d = {"one": 1, "two": 2, "three": 3, 1j: 2j}
for k in d:
- self.assertTrue(k in d)
- self.assertTrue(k not in d.values())
+ self.assertIn(k, d)
+ self.assertNotIn(k, d.values())
for v in d.values():
- self.assertTrue(v in d.values())
- self.assertTrue(v not in d)
+ self.assertIn(v, d.values())
+ self.assertNotIn(v, d)
for k, v in d.items():
- self.assertTrue((k, v) in d.items())
- self.assertTrue((v, k) not in d.items())
+ self.assertIn((k, v), d.items())
+ self.assertNotIn((v, k), d.items())
f = open(TESTFN, "w")
try:
@@ -569,9 +569,9 @@
try:
for chunk in "abc":
f.seek(0, 0)
- self.assertTrue(chunk not in f)
+ self.assertNotIn(chunk, f)
f.seek(0, 0)
- self.assertTrue((chunk + "\n") in f)
+ self.assertIn((chunk + "\n"), f)
finally:
f.close()
try:
Modified: python/branches/py3k-cdecimal/Lib/test/test_logging.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_logging.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_logging.py Thu Jan 21 20:32:23 2010
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2001-2009 by Vinay Sajip. All Rights Reserved.
+# Copyright 2001-2010 by Vinay Sajip. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
@@ -18,7 +18,7 @@
"""Test harness for the logging module. Run all tests.
-Copyright (C) 2001-2009 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2010 Vinay Sajip. All Rights Reserved.
"""
import logging
Modified: python/branches/py3k-cdecimal/Lib/test/test_long.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_long.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_long.py Thu Jan 21 20:32:23 2010
@@ -4,6 +4,7 @@
import random
import math
+import array
# Used for lazy formatting of failure messages
class Frm(object):
@@ -900,6 +901,237 @@
for e in bad_exponents:
self.assertRaises(TypeError, round, 3, e)
+ def test_to_bytes(self):
+ def check(tests, byteorder, signed=False):
+ for test, expected in tests.items():
+ try:
+ self.assertEqual(
+ test.to_bytes(len(expected), byteorder, signed=signed),
+ expected)
+ except Exception as err:
+ raise AssertionError(
+ "failed to convert {0} with byteorder={1} and signed={2}"
+ .format(test, byteorder, signed)) from err
+
+ # Convert integers to signed big-endian byte arrays.
+ tests1 = {
+ 0: b'\x00',
+ 1: b'\x01',
+ -1: b'\xff',
+ -127: b'\x81',
+ -128: b'\x80',
+ -129: b'\xff\x7f',
+ 127: b'\x7f',
+ 129: b'\x00\x81',
+ -255: b'\xff\x01',
+ -256: b'\xff\x00',
+ 255: b'\x00\xff',
+ 256: b'\x01\x00',
+ 32767: b'\x7f\xff',
+ -32768: b'\xff\x80\x00',
+ 65535: b'\x00\xff\xff',
+ -65536: b'\xff\x00\x00',
+ -8388608: b'\x80\x00\x00'
+ }
+ check(tests1, 'big', signed=True)
+
+ # Convert integers to signed little-endian byte arrays.
+ tests2 = {
+ 0: b'\x00',
+ 1: b'\x01',
+ -1: b'\xff',
+ -127: b'\x81',
+ -128: b'\x80',
+ -129: b'\x7f\xff',
+ 127: b'\x7f',
+ 129: b'\x81\x00',
+ -255: b'\x01\xff',
+ -256: b'\x00\xff',
+ 255: b'\xff\x00',
+ 256: b'\x00\x01',
+ 32767: b'\xff\x7f',
+ -32768: b'\x00\x80',
+ 65535: b'\xff\xff\x00',
+ -65536: b'\x00\x00\xff',
+ -8388608: b'\x00\x00\x80'
+ }
+ check(tests2, 'little', signed=True)
+
+ # Convert integers to unsigned big-endian byte arrays.
+ tests3 = {
+ 0: b'\x00',
+ 1: b'\x01',
+ 127: b'\x7f',
+ 128: b'\x80',
+ 255: b'\xff',
+ 256: b'\x01\x00',
+ 32767: b'\x7f\xff',
+ 32768: b'\x80\x00',
+ 65535: b'\xff\xff',
+ 65536: b'\x01\x00\x00'
+ }
+ check(tests3, 'big', signed=False)
+
+ # Convert integers to unsigned little-endian byte arrays.
+ tests4 = {
+ 0: b'\x00',
+ 1: b'\x01',
+ 127: b'\x7f',
+ 128: b'\x80',
+ 255: b'\xff',
+ 256: b'\x00\x01',
+ 32767: b'\xff\x7f',
+ 32768: b'\x00\x80',
+ 65535: b'\xff\xff',
+ 65536: b'\x00\x00\x01'
+ }
+ check(tests4, 'little', signed=False)
+
+ self.assertRaises(OverflowError, (256).to_bytes, 1, 'big', signed=False)
+ self.assertRaises(OverflowError, (256).to_bytes, 1, 'big', signed=True)
+ self.assertRaises(OverflowError, (256).to_bytes, 1, 'little', signed=False)
+ self.assertRaises(OverflowError, (256).to_bytes, 1, 'little', signed=True)
+ self.assertRaises(OverflowError, (-1).to_bytes, 2, 'big', signed=False),
+ self.assertRaises(OverflowError, (-1).to_bytes, 2, 'little', signed=False)
+ self.assertEqual((0).to_bytes(0, 'big'), b'')
+ self.assertEqual((1).to_bytes(5, 'big'), b'\x00\x00\x00\x00\x01')
+ self.assertEqual((0).to_bytes(5, 'big'), b'\x00\x00\x00\x00\x00')
+ self.assertEqual((-1).to_bytes(5, 'big', signed=True),
+ b'\xff\xff\xff\xff\xff')
+ self.assertRaises(OverflowError, (1).to_bytes, 0, 'big')
+
+ def test_from_bytes(self):
+ def check(tests, byteorder, signed=False):
+ for test, expected in tests.items():
+ try:
+ self.assertEqual(
+ int.from_bytes(test, byteorder, signed=signed),
+ expected)
+ except Exception as err:
+ raise AssertionError(
+ "failed to convert {0} with byteorder={1!r} and signed={2}"
+ .format(test, byteorder, signed)) from err
+
+ # Convert signed big-endian byte arrays to integers.
+ tests1 = {
+ b'': 0,
+ b'\x00': 0,
+ b'\x00\x00': 0,
+ b'\x01': 1,
+ b'\x00\x01': 1,
+ b'\xff': -1,
+ b'\xff\xff': -1,
+ b'\x81': -127,
+ b'\x80': -128,
+ b'\xff\x7f': -129,
+ b'\x7f': 127,
+ b'\x00\x81': 129,
+ b'\xff\x01': -255,
+ b'\xff\x00': -256,
+ b'\x00\xff': 255,
+ b'\x01\x00': 256,
+ b'\x7f\xff': 32767,
+ b'\x80\x00': -32768,
+ b'\x00\xff\xff': 65535,
+ b'\xff\x00\x00': -65536,
+ b'\x80\x00\x00': -8388608
+ }
+ check(tests1, 'big', signed=True)
+
+ # Convert signed little-endian byte arrays to integers.
+ tests2 = {
+ b'': 0,
+ b'\x00': 0,
+ b'\x00\x00': 0,
+ b'\x01': 1,
+ b'\x00\x01': 256,
+ b'\xff': -1,
+ b'\xff\xff': -1,
+ b'\x81': -127,
+ b'\x80': -128,
+ b'\x7f\xff': -129,
+ b'\x7f': 127,
+ b'\x81\x00': 129,
+ b'\x01\xff': -255,
+ b'\x00\xff': -256,
+ b'\xff\x00': 255,
+ b'\x00\x01': 256,
+ b'\xff\x7f': 32767,
+ b'\x00\x80': -32768,
+ b'\xff\xff\x00': 65535,
+ b'\x00\x00\xff': -65536,
+ b'\x00\x00\x80': -8388608
+ }
+ check(tests2, 'little', signed=True)
+
+ # Convert unsigned big-endian byte arrays to integers.
+ tests3 = {
+ b'': 0,
+ b'\x00': 0,
+ b'\x01': 1,
+ b'\x7f': 127,
+ b'\x80': 128,
+ b'\xff': 255,
+ b'\x01\x00': 256,
+ b'\x7f\xff': 32767,
+ b'\x80\x00': 32768,
+ b'\xff\xff': 65535,
+ b'\x01\x00\x00': 65536,
+ }
+ check(tests3, 'big', signed=False)
+
+ # Convert integers to unsigned little-endian byte arrays.
+ tests4 = {
+ b'': 0,
+ b'\x00': 0,
+ b'\x01': 1,
+ b'\x7f': 127,
+ b'\x80': 128,
+ b'\xff': 255,
+ b'\x00\x01': 256,
+ b'\xff\x7f': 32767,
+ b'\x00\x80': 32768,
+ b'\xff\xff': 65535,
+ b'\x00\x00\x01': 65536,
+ }
+ check(tests4, 'little', signed=False)
+
+ class myint(int):
+ pass
+
+ self.assertTrue(type(myint.from_bytes(b'\x00', 'big')) is myint)
+ self.assertEqual(myint.from_bytes(b'\x01', 'big'), 1)
+ self.assertTrue(
+ type(myint.from_bytes(b'\x00', 'big', signed=False)) is myint)
+ self.assertEqual(myint.from_bytes(b'\x01', 'big', signed=False), 1)
+ self.assertTrue(type(myint.from_bytes(b'\x00', 'little')) is myint)
+ self.assertEqual(myint.from_bytes(b'\x01', 'little'), 1)
+ self.assertTrue(type(myint.from_bytes(
+ b'\x00', 'little', signed=False)) is myint)
+ self.assertEqual(myint.from_bytes(b'\x01', 'little', signed=False), 1)
+ self.assertEqual(
+ int.from_bytes([255, 0, 0], 'big', signed=True), -65536)
+ self.assertEqual(
+ int.from_bytes((255, 0, 0), 'big', signed=True), -65536)
+ self.assertEqual(int.from_bytes(
+ bytearray(b'\xff\x00\x00'), 'big', signed=True), -65536)
+ self.assertEqual(int.from_bytes(
+ bytearray(b'\xff\x00\x00'), 'big', signed=True), -65536)
+ self.assertEqual(int.from_bytes(
+ array.array('B', b'\xff\x00\x00'), 'big', signed=True), -65536)
+ self.assertEqual(int.from_bytes(
+ memoryview(b'\xff\x00\x00'), 'big', signed=True), -65536)
+ self.assertRaises(ValueError, int.from_bytes, [256], 'big')
+ self.assertRaises(ValueError, int.from_bytes, [0], 'big\x00')
+ self.assertRaises(ValueError, int.from_bytes, [0], 'little\x00')
+ self.assertRaises(TypeError, int.from_bytes, "", 'big')
+ self.assertRaises(TypeError, int.from_bytes, "\x00", 'big')
+ self.assertRaises(TypeError, int.from_bytes, 0, 'big')
+ self.assertRaises(TypeError, int.from_bytes, 0, 'big', True)
+ self.assertRaises(TypeError, myint.from_bytes, "", 'big')
+ self.assertRaises(TypeError, myint.from_bytes, "\x00", 'big')
+ self.assertRaises(TypeError, myint.from_bytes, 0, 'big')
+ self.assertRaises(TypeError, int.from_bytes, 0, 'big', True)
def test_main():
Modified: python/branches/py3k-cdecimal/Lib/test/test_mmap.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_mmap.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_mmap.py Thu Jan 21 20:32:23 2010
@@ -502,7 +502,7 @@
def test_error(self):
self.assertTrue(issubclass(mmap.error, EnvironmentError))
- self.assertTrue("mmap.error" in str(mmap.error))
+ self.assertIn("mmap.error", str(mmap.error))
def test_io_methods(self):
data = b"0123456789"
Modified: python/branches/py3k-cdecimal/Lib/test/test_multiprocessing.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_multiprocessing.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_multiprocessing.py Thu Jan 21 20:32:23 2010
@@ -163,7 +163,7 @@
self.assertEquals(p.authkey, current.authkey)
self.assertEquals(p.is_alive(), False)
self.assertEquals(p.daemon, True)
- self.assertTrue(p not in self.active_children())
+ self.assertNotIn(p, self.active_children())
self.assertTrue(type(self.active_children()) is list)
self.assertEqual(p.exitcode, None)
@@ -171,7 +171,7 @@
self.assertEquals(p.exitcode, None)
self.assertEquals(p.is_alive(), True)
- self.assertTrue(p in self.active_children())
+ self.assertIn(p, self.active_children())
self.assertEquals(q.get(), args[1:])
self.assertEquals(q.get(), kwargs)
@@ -184,7 +184,7 @@
self.assertEquals(p.exitcode, 0)
self.assertEquals(p.is_alive(), False)
- self.assertTrue(p not in self.active_children())
+ self.assertNotIn(p, self.active_children())
def _test_terminate(self):
time.sleep(1000)
@@ -198,7 +198,7 @@
p.start()
self.assertEqual(p.is_alive(), True)
- self.assertTrue(p in self.active_children())
+ self.assertIn(p, self.active_children())
self.assertEqual(p.exitcode, None)
p.terminate()
@@ -208,7 +208,7 @@
self.assertTimingAlmostEqual(join.elapsed, 0.0)
self.assertEqual(p.is_alive(), False)
- self.assertTrue(p not in self.active_children())
+ self.assertNotIn(p, self.active_children())
p.join()
@@ -227,13 +227,13 @@
self.assertEqual(type(self.active_children()), list)
p = self.Process(target=time.sleep, args=(DELTA,))
- self.assertTrue(p not in self.active_children())
+ self.assertNotIn(p, self.active_children())
p.start()
- self.assertTrue(p in self.active_children())
+ self.assertIn(p, self.active_children())
p.join()
- self.assertTrue(p not in self.active_children())
+ self.assertNotIn(p, self.active_children())
def _test_recursion(self, wconn, id):
from multiprocessing import forking
Modified: python/branches/py3k-cdecimal/Lib/test/test_os.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_os.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_os.py Thu Jan 21 20:32:23 2010
@@ -228,7 +228,7 @@
def trunc(x): return x
self.assertEquals(trunc(getattr(result, attr)),
result[getattr(stat, name)])
- self.assertTrue(attr in members)
+ self.assertIn(attr, members)
try:
result[200]
@@ -564,6 +564,14 @@
def test_execvpe_with_bad_arglist(self):
self.assertRaises(ValueError, os.execvpe, 'notepad', [], None)
+class ArgTests(unittest.TestCase):
+ def test_bytearray(self):
+ # Issue #7561: posix module didn't release bytearray exports properly.
+ b = bytearray(os.sep.encode('ascii'))
+ self.assertRaises(OSError, os.mkdir, b)
+ # Check object is still resizable.
+ b[:] = b''
+
class Win32ErrorTests(unittest.TestCase):
def test_rename(self):
self.assertRaises(WindowsError, os.rename, support.TESTFN, support.TESTFN+".bak")
@@ -750,6 +758,7 @@
def test_main():
support.run_unittest(
+ ArgTests,
FileTests,
StatAttributeTests,
EnvironTests,
Modified: python/branches/py3k-cdecimal/Lib/test/test_peepholer.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_peepholer.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_peepholer.py Thu Jan 21 20:32:23 2010
@@ -1,4 +1,5 @@
import dis
+import re
import sys
from io import StringIO
import unittest
@@ -25,9 +26,9 @@
del x
asm = disassemble(unot)
for elem in ('UNARY_NOT', 'POP_JUMP_IF_FALSE'):
- self.assertTrue(elem not in asm)
+ self.assertNotIn(elem, asm)
for elem in ('POP_JUMP_IF_TRUE',):
- self.assertTrue(elem in asm)
+ self.assertIn(elem, asm)
def test_elim_inversion_of_is_or_in(self):
for line, elem in (
@@ -37,7 +38,7 @@
('not a not in b', '(in)',),
):
asm = dis_single(line)
- self.assertTrue(elem in asm)
+ self.assertIn(elem, asm)
def test_global_as_constant(self):
# LOAD_GLOBAL None/True/False --> LOAD_CONST None/True/False
@@ -54,14 +55,14 @@
for func, name in ((f, 'None'), (g, 'True'), (h, 'False')):
asm = disassemble(func)
for elem in ('LOAD_GLOBAL',):
- self.assertTrue(elem not in asm)
+ self.assertNotIn(elem, asm)
for elem in ('LOAD_CONST', '('+name+')'):
- self.assertTrue(elem in asm)
+ self.assertIn(elem, asm)
def f():
'Adding a docstring made this test fail in Py2.5.0'
return None
- self.assertTrue('LOAD_CONST' in disassemble(f))
- self.assertTrue('LOAD_GLOBAL' not in disassemble(f))
+ self.assertIn('LOAD_CONST', disassemble(f))
+ self.assertNotIn('LOAD_GLOBAL', disassemble(f))
def test_while_one(self):
# Skip over: LOAD_CONST trueconst POP_JUMP_IF_FALSE xx
@@ -71,9 +72,9 @@
return list
asm = disassemble(f)
for elem in ('LOAD_CONST', 'POP_JUMP_IF_FALSE'):
- self.assertTrue(elem not in asm)
+ self.assertNotIn(elem, asm)
for elem in ('JUMP_ABSOLUTE',):
- self.assertTrue(elem in asm)
+ self.assertIn(elem, asm)
def test_pack_unpack(self):
for line, elem in (
@@ -82,9 +83,9 @@
('a, b, c = a, b, c', 'ROT_THREE',),
):
asm = dis_single(line)
- self.assertTrue(elem in asm)
- self.assertTrue('BUILD_TUPLE' not in asm)
- self.assertTrue('UNPACK_TUPLE' not in asm)
+ self.assertIn(elem, asm)
+ self.assertNotIn('BUILD_TUPLE', asm)
+ self.assertNotIn('UNPACK_TUPLE', asm)
def test_folding_of_tuples_of_constants(self):
for line, elem in (
@@ -95,8 +96,8 @@
('((1, 2), 3, 4)', '(((1, 2), 3, 4))'),
):
asm = dis_single(line)
- self.assertTrue(elem in asm)
- self.assertTrue('BUILD_TUPLE' not in asm)
+ self.assertIn(elem, asm)
+ self.assertNotIn('BUILD_TUPLE', asm)
# Bug 1053819: Tuple of constants misidentified when presented with:
# . . . opcode_with_arg 100 unary_opcode BUILD_TUPLE 1 . . .
@@ -115,6 +116,54 @@
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
],)
+ def test_folding_of_lists_of_constants(self):
+ for line, elem in (
+ # in/not in constants with BUILD_LIST should be folded to a tuple:
+ ('a in [1,2,3]', '(1, 2, 3)'),
+ ('a not in ["a","b","c"]', "(('a', 'b', 'c'))"),
+ ('a in [None, 1, None]', '((None, 1, None))'),
+ ('a not in [(1, 2), 3, 4]', '(((1, 2), 3, 4))'),
+ ):
+ asm = dis_single(line)
+ self.assertIn(elem, asm)
+ self.assertNotIn('BUILD_LIST', asm)
+
+ def test_folding_of_sets_of_constants(self):
+ for line, elem in (
+ # in/not in constants with BUILD_SET should be folded to a frozenset:
+ ('a in {1,2,3}', frozenset({1, 2, 3})),
+ ('a not in {"a","b","c"}', frozenset({'a', 'c', 'b'})),
+ ('a in {None, 1, None}', frozenset({1, None})),
+ ('a not in {(1, 2), 3, 4}', frozenset({(1, 2), 3, 4})),
+ ('a in {1, 2, 3, 3, 2, 1}', frozenset({1, 2, 3})),
+ ):
+ asm = dis_single(line)
+ self.assertNotIn('BUILD_SET', asm)
+
+ # Verify that the frozenset 'elem' is in the disassembly
+ # The ordering of the elements in repr( frozenset ) isn't
+ # guaranteed, so we jump through some hoops to ensure that we have
+ # the frozenset we expect:
+ self.assertIn('frozenset', asm)
+ # Extract the frozenset literal from the disassembly:
+ m = re.match(r'.*(frozenset\({.*}\)).*', asm, re.DOTALL)
+ self.assertTrue(m)
+ self.assertEqual(eval(m.group(1)), elem)
+
+ # Ensure that the resulting code actually works:
+ def f(a):
+ return a in {1, 2, 3}
+
+ def g(a):
+ return a not in {1, 2, 3}
+
+ self.assertTrue(f(3))
+ self.assertTrue(not f(4))
+
+ self.assertTrue(not g(3))
+ self.assertTrue(g(4))
+
+
def test_folding_of_binops_on_constants(self):
for line, elem in (
('a = 2+3+4', '(9)'), # chained fold
@@ -134,17 +183,17 @@
('a = 13 | 7', '(15)'), # binary or
):
asm = dis_single(line)
- self.assertTrue(elem in asm, asm)
- self.assertTrue('BINARY_' not in asm)
+ self.assertIn(elem, asm, asm)
+ self.assertNotIn('BINARY_', asm)
# Verify that unfoldables are skipped
asm = dis_single('a=2+"b"')
- self.assertTrue('(2)' in asm)
- self.assertTrue("('b')" in asm)
+ self.assertIn('(2)', asm)
+ self.assertIn("('b')", asm)
# Verify that large sequences do not result from folding
asm = dis_single('a="x"*1000')
- self.assertTrue('(1000)' in asm)
+ self.assertIn('(1000)', asm)
def test_folding_of_unaryops_on_constants(self):
for line, elem in (
@@ -153,8 +202,8 @@
('+1', '(1)'), # unary positive
):
asm = dis_single(line)
- self.assertTrue(elem in asm, asm)
- self.assertTrue('UNARY_' not in asm)
+ self.assertIn(elem, asm, asm)
+ self.assertNotIn('UNARY_', asm)
# Verify that unfoldables are skipped
for line, elem in (
@@ -162,16 +211,16 @@
('~"abc"', "('abc')"), # unary invert
):
asm = dis_single(line)
- self.assertTrue(elem in asm, asm)
- self.assertTrue('UNARY_' in asm)
+ self.assertIn(elem, asm, asm)
+ self.assertIn('UNARY_', asm)
def test_elim_extra_return(self):
# RETURN LOAD_CONST None RETURN --> RETURN
def f(x):
return x
asm = disassemble(f)
- self.assertTrue('LOAD_CONST' not in asm)
- self.assertTrue('(None)' not in asm)
+ self.assertNotIn('LOAD_CONST', asm)
+ self.assertNotIn('(None)', asm)
self.assertEqual(asm.split().count('RETURN_VALUE'), 1)
def test_elim_jump_to_return(self):
@@ -179,8 +228,8 @@
def f(cond, true_value, false_value):
return true_value if cond else false_value
asm = disassemble(f)
- self.assertTrue('JUMP_FORWARD' not in asm)
- self.assertTrue('JUMP_ABSOLUTE' not in asm)
+ self.assertNotIn('JUMP_FORWARD', asm)
+ self.assertNotIn('JUMP_ABSOLUTE', asm)
self.assertEqual(asm.split().count('RETURN_VALUE'), 2)
def test_elim_jump_after_return1(self):
@@ -195,8 +244,8 @@
return 5
return 6
asm = disassemble(f)
- self.assertTrue('JUMP_FORWARD' not in asm)
- self.assertTrue('JUMP_ABSOLUTE' not in asm)
+ self.assertNotIn('JUMP_FORWARD', asm)
+ self.assertNotIn('JUMP_ABSOLUTE', asm)
self.assertEqual(asm.split().count('RETURN_VALUE'), 6)
def test_elim_jump_after_return2(self):
@@ -205,7 +254,7 @@
while 1:
if cond1: return 4
asm = disassemble(f)
- self.assertTrue('JUMP_FORWARD' not in asm)
+ self.assertNotIn('JUMP_FORWARD', asm)
# There should be one jump for the while loop.
self.assertEqual(asm.split().count('JUMP_ABSOLUTE'), 1)
self.assertEqual(asm.split().count('RETURN_VALUE'), 2)
@@ -216,7 +265,7 @@
pass
return g
asm = disassemble(f)
- self.assertTrue('BINARY_ADD' not in asm)
+ self.assertNotIn('BINARY_ADD', asm)
def test_main(verbose=None):
Modified: python/branches/py3k-cdecimal/Lib/test/test_pep352.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_pep352.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_pep352.py Thu Jan 21 20:32:23 2010
@@ -73,7 +73,7 @@
self.verify_instance_interface(exc())
except TypeError:
pass
- self.assertTrue(exc_name in exc_set)
+ self.assertIn(exc_name, exc_set)
exc_set.discard(exc_name)
last_exc = exc
last_depth = depth
Modified: python/branches/py3k-cdecimal/Lib/test/test_poplib.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_poplib.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_poplib.py Thu Jan 21 20:32:23 2010
@@ -258,7 +258,7 @@
self.client = poplib.POP3_SSL(self.server.host, self.server.port)
def test__all__(self):
- self.assertTrue('POP3_SSL' in poplib.__all__)
+ self.assertIn('POP3_SSL', poplib.__all__)
class TestTimeouts(TestCase):
Modified: python/branches/py3k-cdecimal/Lib/test/test_posix.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_posix.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_posix.py Thu Jan 21 20:32:23 2010
@@ -251,7 +251,7 @@
def test_lsdir(self):
if hasattr(posix, 'lsdir'):
- self.assertTrue(support.TESTFN in posix.lsdir(os.curdir))
+ self.assertIn(support.TESTFN, posix.lsdir(os.curdir))
def test_access(self):
if hasattr(posix, 'access'):
Modified: python/branches/py3k-cdecimal/Lib/test/test_posixpath.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_posixpath.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_posixpath.py Thu Jan 21 20:32:23 2010
@@ -481,14 +481,14 @@
self.assertRaises(TypeError, posixpath.normpath)
def test_abspath(self):
- self.assertTrue("foo" in posixpath.abspath("foo"))
- self.assertTrue(b"foo" in posixpath.abspath(b"foo"))
+ self.assertIn("foo", posixpath.abspath("foo"))
+ self.assertIn(b"foo", posixpath.abspath(b"foo"))
self.assertRaises(TypeError, posixpath.abspath)
def test_realpath(self):
- self.assertTrue("foo" in realpath("foo"))
- self.assertTrue(b"foo" in realpath(b"foo"))
+ self.assertIn("foo", realpath("foo"))
+ self.assertIn(b"foo", realpath(b"foo"))
self.assertRaises(TypeError, posixpath.realpath)
if hasattr(os, "symlink"):
Modified: python/branches/py3k-cdecimal/Lib/test/test_pwd.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_pwd.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_pwd.py Thu Jan 21 20:32:23 2010
@@ -43,8 +43,8 @@
for e in entries:
if not e[0] or e[0] == '+':
continue # skip NIS entries etc.
- self.assertTrue(pwd.getpwnam(e.pw_name) in entriesbyname[e.pw_name])
- self.assertTrue(pwd.getpwuid(e.pw_uid) in entriesbyuid[e.pw_uid])
+ self.assertIn(pwd.getpwnam(e.pw_name), entriesbyname[e.pw_name])
+ self.assertIn(pwd.getpwuid(e.pw_uid), entriesbyuid[e.pw_uid])
def test_errors(self):
self.assertRaises(TypeError, pwd.getpwuid)
Modified: python/branches/py3k-cdecimal/Lib/test/test_pyclbr.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_pyclbr.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_pyclbr.py Thu Jan 21 20:32:23 2010
@@ -40,6 +40,7 @@
if key in ignore: return
if key not in obj:
print("***",key, file=sys.stderr)
+ self.assertIn(key, obj)
self.assertTrue(key in obj, "%r in %r" % (key, obj))
def assertEqualsOrIgnored(self, a, b, ignore):
Modified: python/branches/py3k-cdecimal/Lib/test/test_pydoc.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_pydoc.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_pydoc.py Thu Jan 21 20:32:23 2010
@@ -313,7 +313,7 @@
# Check that pydocfodder module can be described
from test import pydocfodder
doc = pydoc.render_doc(pydocfodder)
- self.assertTrue("pydocfodder" in doc)
+ self.assertIn("pydocfodder", doc)
def test_classic_class(self):
class C: "Classic class"
@@ -321,7 +321,7 @@
self.assertEqual(pydoc.describe(C), 'class C')
self.assertEqual(pydoc.describe(c), 'C')
expected = 'C in module %s' % __name__
- self.assertTrue(expected in pydoc.render_doc(c))
+ self.assertIn(expected, pydoc.render_doc(c))
def test_class(self):
class C(object): "New-style class"
@@ -330,7 +330,7 @@
self.assertEqual(pydoc.describe(C), 'class C')
self.assertEqual(pydoc.describe(c), 'C')
expected = 'C in module %s object' % __name__
- self.assertTrue(expected in pydoc.render_doc(c))
+ self.assertIn(expected, pydoc.render_doc(c))
def test_main():
Modified: python/branches/py3k-cdecimal/Lib/test/test_raise.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_raise.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_raise.py Thu Jan 21 20:32:23 2010
@@ -28,7 +28,7 @@
try:
raise
except RuntimeError as e:
- self.assertTrue("No active exception" in str(e))
+ self.assertIn("No active exception", str(e))
else:
self.fail("No exception raised")
@@ -127,7 +127,7 @@
try:
raise IndexError from 5
except TypeError as e:
- self.assertTrue("exception cause" in str(e))
+ self.assertIn("exception cause", str(e))
else:
self.fail("No exception raised")
Modified: python/branches/py3k-cdecimal/Lib/test/test_random.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_random.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_random.py Thu Jan 21 20:32:23 2010
@@ -211,7 +211,7 @@
n += n - 1 # check 1 below the next power of two
k = int(1.00001 + _log(n, 2))
- self.assertTrue(k in [numbits, numbits+1])
+ self.assertIn(k, [numbits, numbits+1])
self.assertTrue(2**k > n > 2**(k-2))
n -= n >> 15 # check a little farther below the next power of two
@@ -367,7 +367,7 @@
n += n - 1 # check 1 below the next power of two
k = int(1.00001 + _log(n, 2))
- self.assertTrue(k in [numbits, numbits+1])
+ self.assertIn(k, [numbits, numbits+1])
self.assertTrue(2**k > n > 2**(k-2))
n -= n >> 15 # check a little farther below the next power of two
Modified: python/branches/py3k-cdecimal/Lib/test/test_range.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_range.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_range.py Thu Jan 21 20:32:23 2010
@@ -59,18 +59,18 @@
self.assertEqual(list(range(a+4, a, -2)), [a+4, a+2])
seq = list(range(a, b, c))
- self.assertTrue(a in seq)
- self.assertTrue(b not in seq)
+ self.assertIn(a, seq)
+ self.assertNotIn(b, seq)
self.assertEqual(len(seq), 2)
seq = list(range(b, a, -c))
- self.assertTrue(b in seq)
- self.assertTrue(a not in seq)
+ self.assertIn(b, seq)
+ self.assertNotIn(a, seq)
self.assertEqual(len(seq), 2)
seq = list(range(-a, -b, -c))
- self.assertTrue(-a in seq)
- self.assertTrue(-b not in seq)
+ self.assertIn(-a, seq)
+ self.assertNotIn(-b, seq)
self.assertEqual(len(seq), 2)
self.assertRaises(TypeError, range)
@@ -114,13 +114,13 @@
def test_types(self):
# Non-integer objects *equal* to any of the range's items are supposed
# to be contained in the range.
- self.assertTrue(1.0 in range(3))
- self.assertTrue(True in range(3))
- self.assertTrue(1+0j in range(3))
+ self.assertIn(1.0, range(3))
+ self.assertIn(True, range(3))
+ self.assertIn(1+0j, range(3))
class C1:
def __eq__(self, other): return True
- self.assertTrue(C1() in range(3))
+ self.assertIn(C1(), range(3))
# Objects are never coerced into other types for comparison.
class C2:
@@ -128,32 +128,32 @@
def __index__(self): return 1
self.assertFalse(C2() in range(3))
# ..except if explicitly told so.
- self.assertTrue(int(C2()) in range(3))
+ self.assertIn(int(C2()), range(3))
# Check that the range.__contains__ optimization is only
# used for ints, not for instances of subclasses of int.
class C3(int):
def __eq__(self, other): return True
- self.assertTrue(C3(11) in range(10))
- self.assertTrue(C3(11) in list(range(10)))
+ self.assertIn(C3(11), range(10))
+ self.assertIn(C3(11), list(range(10)))
def test_strided_limits(self):
r = range(0, 101, 2)
- self.assertTrue(0 in r)
+ self.assertIn(0, r)
self.assertFalse(1 in r)
- self.assertTrue(2 in r)
+ self.assertIn(2, r)
self.assertFalse(99 in r)
- self.assertTrue(100 in r)
+ self.assertIn(100, r)
self.assertFalse(101 in r)
r = range(0, -20, -1)
- self.assertTrue(0 in r)
- self.assertTrue(-1 in r)
- self.assertTrue(-19 in r)
+ self.assertIn(0, r)
+ self.assertIn(-1, r)
+ self.assertIn(-19, r)
self.assertFalse(-20 in r)
r = range(0, -20, -2)
- self.assertTrue(-18 in r)
+ self.assertIn(-18, r)
self.assertFalse(-19 in r)
self.assertFalse(-20 in r)
Modified: python/branches/py3k-cdecimal/Lib/test/test_re.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_re.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_re.py Thu Jan 21 20:32:23 2010
@@ -717,6 +717,12 @@
self.assertRaises(ValueError, re.compile, '(?a)\w', re.UNICODE)
self.assertRaises(ValueError, re.compile, '(?au)\w')
+ def test_dealloc(self):
+ # issue 3299: check for segfault in debug build
+ import _sre
+ long_overflow = sys.maxsize + 2
+ self.assertRaises(TypeError, re.finditer, "a", {})
+ self.assertRaises(OverflowError, _sre.compile, "abc", 0, [long_overflow])
def run_re_tests():
from test.re_tests import benchmarks, tests, SUCCEED, FAIL, SYNTAX_ERROR
Modified: python/branches/py3k-cdecimal/Lib/test/test_reprlib.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_reprlib.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_reprlib.py Thu Jan 21 20:32:23 2010
@@ -125,7 +125,7 @@
s = r(ClassWithFailingRepr)
self.assertTrue(s.startswith("<class "))
self.assertTrue(s.endswith(">"))
- self.assertTrue(s.find("...") in [12, 13])
+ self.assertIn(s.find("..."), [12, 13])
def test_lambda(self):
self.assertTrue(repr(lambda x: x).startswith(
Modified: python/branches/py3k-cdecimal/Lib/test/test_runpy.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_runpy.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_runpy.py Thu Jan 21 20:32:23 2010
@@ -165,14 +165,14 @@
try:
if verbose: print("Running from source:", mod_name)
d1 = run_module(mod_name) # Read from source
- self.assertTrue("x" in d1)
+ self.assertIn("x", d1)
self.assertEqual(d1["x"], 1)
del d1 # Ensure __loader__ entry doesn't keep file open
__import__(mod_name)
os.remove(mod_fname)
if verbose: print("Running from compiled:", mod_name)
d2 = run_module(mod_name) # Read from bytecode
- self.assertTrue("x" in d2)
+ self.assertIn("x", d2)
self.assertEqual(d2["x"], 1)
del d2 # Ensure __loader__ entry doesn't keep file open
finally:
@@ -187,14 +187,14 @@
try:
if verbose: print("Running from source:", pkg_name)
d1 = run_module(pkg_name) # Read from source
- self.assertTrue("x" in d1)
+ self.assertIn("x", d1)
self.assertTrue(d1["x"] == 1)
del d1 # Ensure __loader__ entry doesn't keep file open
__import__(mod_name)
os.remove(mod_fname)
if verbose: print("Running from compiled:", pkg_name)
d2 = run_module(pkg_name) # Read from bytecode
- self.assertTrue("x" in d2)
+ self.assertIn("x", d2)
self.assertTrue(d2["x"] == 1)
del d2 # Ensure __loader__ entry doesn't keep file open
finally:
@@ -239,19 +239,19 @@
pkg_name = mod_name.rpartition('.')[0]
if verbose: print("Running from source:", mod_name)
d1 = run_module(mod_name, run_name=run_name) # Read from source
- self.assertTrue("__package__" in d1)
+ self.assertIn("__package__", d1)
self.assertTrue(d1["__package__"] == pkg_name)
- self.assertTrue("sibling" in d1)
- self.assertTrue("nephew" in d1)
+ self.assertIn("sibling", d1)
+ self.assertIn("nephew", d1)
del d1 # Ensure __loader__ entry doesn't keep file open
__import__(mod_name)
os.remove(mod_fname)
if verbose: print("Running from compiled:", mod_name)
d2 = run_module(mod_name, run_name=run_name) # Read from bytecode
- self.assertTrue("__package__" in d2)
+ self.assertIn("__package__", d2)
self.assertTrue(d2["__package__"] == pkg_name)
- self.assertTrue("sibling" in d2)
- self.assertTrue("nephew" in d2)
+ self.assertIn("sibling", d2)
+ self.assertIn("nephew", d2)
del d2 # Ensure __loader__ entry doesn't keep file open
finally:
self._del_pkg(pkg_dir, depth, mod_name)
Modified: python/branches/py3k-cdecimal/Lib/test/test_sax.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_sax.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_sax.py Thu Jan 21 20:32:23 2010
@@ -59,7 +59,7 @@
self.assertEquals(attrs.getNames(), ["attr"])
self.assertEquals(attrs.getQNames(), ["attr"])
self.assertEquals(len(attrs), 1)
- self.assertTrue("attr" in attrs)
+ self.assertIn("attr", attrs)
self.assertEquals(list(attrs.keys()), ["attr"])
self.assertEquals(attrs.get("attr"), "val")
self.assertEquals(attrs.get("attr", 25), "val")
@@ -436,7 +436,7 @@
self.assertTrue((attrs.getQNames() == [] or
attrs.getQNames() == ["ns:attr"]))
self.assertEquals(len(attrs), 1)
- self.assertTrue((ns_uri, "attr") in attrs)
+ self.assertIn((ns_uri, "attr"), attrs)
self.assertEquals(attrs.get((ns_uri, "attr")), "val")
self.assertEquals(attrs.get((ns_uri, "attr"), 25), "val")
self.assertEquals(list(attrs.items()), [((ns_uri, "attr"), "val")])
@@ -626,7 +626,7 @@
self.assertEquals(attrs.getNames(), [(ns_uri, "attr")])
self.assertEquals(attrs.getQNames(), ["ns:attr"])
self.assertEquals(len(attrs), 1)
- self.assertTrue((ns_uri, "attr") in attrs)
+ self.assertIn((ns_uri, "attr"), attrs)
self.assertEquals(list(attrs.keys()), [(ns_uri, "attr")])
self.assertEquals(attrs.get((ns_uri, "attr")), "val")
self.assertEquals(attrs.get((ns_uri, "attr"), 25), "val")
Modified: python/branches/py3k-cdecimal/Lib/test/test_scope.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_scope.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_scope.py Thu Jan 21 20:32:23 2010
@@ -447,7 +447,7 @@
return g
d = f(2)(4)
- self.assertTrue('h' in d)
+ self.assertIn('h', d)
del d['h']
self.assertEqual(d, {'x': 2, 'y': 7, 'w': 6})
@@ -481,8 +481,8 @@
return C
varnames = f(1).z
- self.assertTrue("x" not in varnames)
- self.assertTrue("y" in varnames)
+ self.assertNotIn("x", varnames)
+ self.assertIn("y", varnames)
def testLocalsClass_WithTrace(self):
# Issue23728: after the trace function returns, the locals()
@@ -660,7 +660,7 @@
c = f(0)
self.assertEqual(c.get(), 1)
- self.assertTrue("x" not in c.__class__.__dict__)
+ self.assertNotIn("x", c.__class__.__dict__)
def testNonLocalGenerator(self):
Modified: python/branches/py3k-cdecimal/Lib/test/test_set.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_set.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_set.py Thu Jan 21 20:32:23 2010
@@ -65,7 +65,7 @@
self.assertEqual(c in self.s, c in self.d)
self.assertRaises(TypeError, self.s.__contains__, [[]])
s = self.thetype([frozenset(self.letters)])
- self.assertTrue(self.thetype(self.letters) in s)
+ self.assertIn(self.thetype(self.letters), s)
def test_union(self):
u = self.s.union(self.otherword)
@@ -269,7 +269,7 @@
s=H()
f=set()
f.add(s)
- self.assertTrue(s in f)
+ self.assertIn(s, f)
f.remove(s)
f.add(s)
f.discard(s)
@@ -379,7 +379,7 @@
def test_add(self):
self.s.add('Q')
- self.assertTrue('Q' in self.s)
+ self.assertIn('Q', self.s)
dup = self.s.copy()
self.s.add('Q')
self.assertEqual(self.s, dup)
@@ -387,13 +387,13 @@
def test_remove(self):
self.s.remove('a')
- self.assertTrue('a' not in self.s)
+ self.assertNotIn('a', self.s)
self.assertRaises(KeyError, self.s.remove, 'Q')
self.assertRaises(TypeError, self.s.remove, [])
s = self.thetype([frozenset(self.word)])
- self.assertTrue(self.thetype(self.word) in s)
+ self.assertIn(self.thetype(self.word), s)
s.remove(self.thetype(self.word))
- self.assertTrue(self.thetype(self.word) not in s)
+ self.assertNotIn(self.thetype(self.word), s)
self.assertRaises(KeyError, self.s.remove, self.thetype(self.word))
def test_remove_keyerror_unpacking(self):
@@ -420,26 +420,26 @@
def test_discard(self):
self.s.discard('a')
- self.assertTrue('a' not in self.s)
+ self.assertNotIn('a', self.s)
self.s.discard('Q')
self.assertRaises(TypeError, self.s.discard, [])
s = self.thetype([frozenset(self.word)])
- self.assertTrue(self.thetype(self.word) in s)
+ self.assertIn(self.thetype(self.word), s)
s.discard(self.thetype(self.word))
- self.assertTrue(self.thetype(self.word) not in s)
+ self.assertNotIn(self.thetype(self.word), s)
s.discard(self.thetype(self.word))
def test_pop(self):
for i in range(len(self.s)):
elem = self.s.pop()
- self.assertTrue(elem not in self.s)
+ self.assertNotIn(elem, self.s)
self.assertRaises(KeyError, self.s.pop)
def test_update(self):
retval = self.s.update(self.otherword)
self.assertEqual(retval, None)
for c in (self.word + self.otherword):
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
self.assertRaises(PassThru, self.s.update, check_pass_thru())
self.assertRaises(TypeError, self.s.update, [[]])
for p, q in (('cdc', 'abcd'), ('efgfe', 'abcefg'), ('ccb', 'abc'), ('ef', 'abcef')):
@@ -457,16 +457,16 @@
def test_ior(self):
self.s |= set(self.otherword)
for c in (self.word + self.otherword):
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
def test_intersection_update(self):
retval = self.s.intersection_update(self.otherword)
self.assertEqual(retval, None)
for c in (self.word + self.otherword):
if c in self.otherword and c in self.word:
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
else:
- self.assertTrue(c not in self.s)
+ self.assertNotIn(c, self.s)
self.assertRaises(PassThru, self.s.intersection_update, check_pass_thru())
self.assertRaises(TypeError, self.s.intersection_update, [[]])
for p, q in (('cdc', 'c'), ('efgfe', ''), ('ccb', 'bc'), ('ef', '')):
@@ -484,18 +484,18 @@
self.s &= set(self.otherword)
for c in (self.word + self.otherword):
if c in self.otherword and c in self.word:
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
else:
- self.assertTrue(c not in self.s)
+ self.assertNotIn(c, self.s)
def test_difference_update(self):
retval = self.s.difference_update(self.otherword)
self.assertEqual(retval, None)
for c in (self.word + self.otherword):
if c in self.word and c not in self.otherword:
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
else:
- self.assertTrue(c not in self.s)
+ self.assertNotIn(c, self.s)
self.assertRaises(PassThru, self.s.difference_update, check_pass_thru())
self.assertRaises(TypeError, self.s.difference_update, [[]])
self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]])
@@ -521,18 +521,18 @@
self.s -= set(self.otherword)
for c in (self.word + self.otherword):
if c in self.word and c not in self.otherword:
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
else:
- self.assertTrue(c not in self.s)
+ self.assertNotIn(c, self.s)
def test_symmetric_difference_update(self):
retval = self.s.symmetric_difference_update(self.otherword)
self.assertEqual(retval, None)
for c in (self.word + self.otherword):
if (c in self.word) ^ (c in self.otherword):
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
else:
- self.assertTrue(c not in self.s)
+ self.assertNotIn(c, self.s)
self.assertRaises(PassThru, self.s.symmetric_difference_update, check_pass_thru())
self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]])
for p, q in (('cdc', 'abd'), ('efgfe', 'abcefg'), ('ccb', 'a'), ('ef', 'abcef')):
@@ -545,9 +545,9 @@
self.s ^= set(self.otherword)
for c in (self.word + self.otherword):
if (c in self.word) ^ (c in self.otherword):
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
else:
- self.assertTrue(c not in self.s)
+ self.assertNotIn(c, self.s)
def test_inplace_on_self(self):
t = self.s.copy()
@@ -814,7 +814,7 @@
def test_iteration(self):
for v in self.set:
- self.assertTrue(v in self.values)
+ self.assertIn(v, self.values)
setiter = iter(self.set)
# note: __length_hint__ is an internal undocumented API,
# don't rely on it in your own programs
@@ -849,10 +849,10 @@
self.repr = "{3}"
def test_in(self):
- self.assertTrue(3 in self.set)
+ self.assertIn(3, self.set)
def test_not_in(self):
- self.assertTrue(2 not in self.set)
+ self.assertNotIn(2, self.set)
#------------------------------------------------------------------------------
@@ -866,10 +866,10 @@
self.repr = "{(0, 'zero')}"
def test_in(self):
- self.assertTrue((0, "zero") in self.set)
+ self.assertIn((0, "zero"), self.set)
def test_not_in(self):
- self.assertTrue(9 not in self.set)
+ self.assertNotIn(9, self.set)
#------------------------------------------------------------------------------
@@ -1186,7 +1186,7 @@
popped[self.set.pop()] = None
self.assertEqual(len(popped), len(self.values))
for v in self.values:
- self.assertTrue(v in popped)
+ self.assertIn(v, popped)
def test_update_empty_tuple(self):
self.set.update(())
@@ -1760,7 +1760,7 @@
edge = vertex # Cuboctahedron vertices are edges in Cube
self.assertEqual(len(edge), 2) # Two cube vertices define an edge
for cubevert in edge:
- self.assertTrue(cubevert in g)
+ self.assertIn(cubevert, g)
#==============================================================================
Modified: python/branches/py3k-cdecimal/Lib/test/test_site.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_site.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_site.py Thu Jan 21 20:32:23 2010
@@ -270,7 +270,7 @@
site.removeduppaths()
seen_paths = set()
for path in sys.path:
- self.assertTrue(path not in seen_paths)
+ self.assertNotIn(path, seen_paths)
seen_paths.add(path)
def test_add_build_dir(self):
Modified: python/branches/py3k-cdecimal/Lib/test/test_socket.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_socket.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_socket.py Thu Jan 21 20:32:23 2010
@@ -502,7 +502,7 @@
# it reasonable to get the host's addr in addition to 0.0.0.0.
# At least for eCos. This is required for the S/390 to pass.
my_ip_addr = socket.gethostbyname(socket.gethostname())
- self.assertTrue(name[0] in ("0.0.0.0", my_ip_addr), '%s invalid' % name[0])
+ self.assertIn(name[0], ("0.0.0.0", my_ip_addr), '%s invalid' % name[0])
self.assertEqual(name[1], port)
def testGetSockOpt(self):
Modified: python/branches/py3k-cdecimal/Lib/test/test_structseq.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_structseq.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_structseq.py Thu Jan 21 20:32:23 2010
@@ -50,8 +50,8 @@
def test_contains(self):
t1 = time.gmtime()
for item in t1:
- self.assertTrue(item in t1)
- self.assertTrue(-42 not in t1)
+ self.assertIn(item, t1)
+ self.assertNotIn(-42, t1)
def test_hash(self):
t1 = time.gmtime()
Modified: python/branches/py3k-cdecimal/Lib/test/test_subprocess.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_subprocess.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_subprocess.py Thu Jan 21 20:32:23 2010
@@ -77,7 +77,7 @@
# check_output() function with zero return code
output = subprocess.check_output(
[sys.executable, "-c", "print('BDFL')"])
- self.assertTrue(b'BDFL' in output)
+ self.assertIn(b'BDFL', output)
def test_check_output_nonzero(self):
# check_call() function with non-zero return code
@@ -94,7 +94,7 @@
output = subprocess.check_output(
[sys.executable, "-c", "import sys; sys.stderr.write('BDFL')"],
stderr=subprocess.STDOUT)
- self.assertTrue(b'BDFL' in output)
+ self.assertIn(b'BDFL', output)
def test_check_output_stdout_arg(self):
# check_output() function stderr redirected to stdout
@@ -103,7 +103,7 @@
[sys.executable, "-c", "print('will not be run')"],
stdout=sys.stdout)
except ValueError as e:
- self.assertTrue('stdout' in e.args[0])
+ self.assertIn('stdout', e.args[0])
else:
self.fail("Expected ValueError when stdout arg supplied.")
Modified: python/branches/py3k-cdecimal/Lib/test/test_sys.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_sys.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_sys.py Thu Jan 21 20:32:23 2010
@@ -318,8 +318,8 @@
d = sys._current_frames()
main_id = _thread.get_ident()
- self.assertTrue(main_id in d)
- self.assertTrue(thread_id in d)
+ self.assertIn(main_id, d)
+ self.assertIn(thread_id, d)
# Verify that the captured main-thread frame is _this_ frame.
frame = d.pop(main_id)
@@ -341,7 +341,7 @@
# And the next record must be for g456().
filename, lineno, funcname, sourceline = stack[i+1]
self.assertEqual(funcname, "g456")
- self.assertTrue(sourceline in ["leave_g.wait()", "entered_g.set()"])
+ self.assertIn(sourceline, ["leave_g.wait()", "entered_g.set()"])
# Reap the spawned thread.
leave_g.set()
@@ -353,13 +353,13 @@
# "thread id" 0.
d = sys._current_frames()
self.assertEqual(len(d), 1)
- self.assertTrue(0 in d)
+ self.assertIn(0, d)
self.assertTrue(d[0] is sys._getframe())
def test_attributes(self):
self.assertTrue(isinstance(sys.api_version, int))
self.assertTrue(isinstance(sys.argv, list))
- self.assertTrue(sys.byteorder in ("little", "big"))
+ self.assertIn(sys.byteorder, ("little", "big"))
self.assertTrue(isinstance(sys.builtin_module_names, tuple))
self.assertTrue(isinstance(sys.copyright, str))
self.assertTrue(isinstance(sys.exec_prefix, str))
@@ -383,7 +383,7 @@
self.assertTrue(isinstance(vi[0], int))
self.assertTrue(isinstance(vi[1], int))
self.assertTrue(isinstance(vi[2], int))
- self.assertTrue(vi[3] in ("alpha", "beta", "candidate", "final"))
+ self.assertIn(vi[3], ("alpha", "beta", "candidate", "final"))
self.assertTrue(isinstance(vi[4], int))
self.assertTrue(isinstance(vi.major, int))
self.assertTrue(isinstance(vi.minor, int))
@@ -398,7 +398,7 @@
self.assertEqual(vi[4], vi.serial)
self.assertTrue(vi > (1,0,0))
self.assertIsInstance(sys.float_repr_style, str)
- self.assertTrue(sys.float_repr_style in ('short', 'legacy'))
+ self.assertIn(sys.float_repr_style, ('short', 'legacy'))
def test_43581(self):
# Can't use sys.stdout, as this is a StringIO object when
Modified: python/branches/py3k-cdecimal/Lib/test/test_tarfile.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_tarfile.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_tarfile.py Thu Jan 21 20:32:23 2010
@@ -485,7 +485,7 @@
def test_find_ustar_longname(self):
name = "ustar/" + "12345/" * 39 + "1234567/longname"
- self.assertTrue(name in self.tar.getnames())
+ self.assertIn(name, self.tar.getnames())
def test_find_regtype_oldv7(self):
tarinfo = self.tar.getmember("misc/regtype-old-v7")
Modified: python/branches/py3k-cdecimal/Lib/test/test_telnetlib.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_telnetlib.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_telnetlib.py Thu Jan 21 20:32:23 2010
@@ -284,7 +284,7 @@
txt = telnet.read_all()
cmd = nego.seen
self.assertTrue(len(cmd) > 0) # we expect at least one command
- self.assertTrue(cmd[:1] in self.cmds)
+ self.assertIn(cmd[:1], self.cmds)
self.assertEqual(cmd[1:2], tl.NOOPT)
self.assertEqual(data_len, len(txt + cmd))
nego.sb_getter = None # break the nego => telnet cycle
@@ -331,7 +331,7 @@
telnet = test_telnet([a])
telnet.set_debuglevel(1)
txt = telnet.read_all()
- self.assertTrue(b in telnet._messages)
+ self.assertIn(b, telnet._messages)
return
def test_debuglevel_write(self):
@@ -339,7 +339,7 @@
telnet.set_debuglevel(1)
telnet.write(b'xxx')
expected = "send b'xxx'\n"
- self.assertTrue(expected in telnet._messages)
+ self.assertIn(expected, telnet._messages)
def test_main(verbose=None):
support.run_unittest(GeneralTests, ReadTests, WriteTests, OptionTests)
Modified: python/branches/py3k-cdecimal/Lib/test/test_tempfile.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_tempfile.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_tempfile.py Thu Jan 21 20:32:23 2010
@@ -160,14 +160,14 @@
for envname in 'TMPDIR', 'TEMP', 'TMP':
dirname = os.getenv(envname)
if not dirname: raise ValueError
- self.assertTrue(dirname in cand)
+ self.assertIn(dirname, cand)
try:
dirname = os.getcwd()
except (AttributeError, os.error):
dirname = os.curdir
- self.assertTrue(dirname in cand)
+ self.assertIn(dirname, cand)
# Not practical to try to verify the presence of OS-specific
# paths in this list.
Modified: python/branches/py3k-cdecimal/Lib/test/test_threading.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_threading.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_threading.py Thu Jan 21 20:32:23 2010
@@ -153,7 +153,7 @@
tid = _thread.start_new_thread(f, (mutex,))
# Wait for the thread to finish.
mutex.acquire()
- self.assertTrue(tid in threading._active)
+ self.assertIn(tid, threading._active)
self.assertTrue(isinstance(threading._active[tid],
threading._DummyThread))
del threading._active[tid]
Modified: python/branches/py3k-cdecimal/Lib/test/test_threading_local.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_threading_local.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_threading_local.py Thu Jan 21 20:32:23 2010
@@ -40,7 +40,7 @@
local.someothervar = None
gc.collect()
deadlist = [weak for weak in weaklist if weak() is None]
- self.assertTrue(len(deadlist) in (n-1, n), (n, len(deadlist)))
+ self.assertIn(len(deadlist), (n-1, n), (n, len(deadlist)))
def test_derived(self):
# Issue 3088: if there is a threads switch inside the __init__
Modified: python/branches/py3k-cdecimal/Lib/test/test_traceback.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_traceback.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_traceback.py Thu Jan 21 20:32:23 2010
@@ -41,12 +41,12 @@
SyntaxError)
self.assertEqual(len(err), 4)
self.assertTrue(err[1].strip() == "return x!")
- self.assertTrue("^" in err[2]) # third line has caret
+ self.assertIn("^", err[2]) # third line has caret
self.assertEqual(err[1].find("!"), err[2].find("^")) # in the right place
err = self.get_exception_format(self.syntax_error_with_caret_2,
SyntaxError)
- self.assertTrue("^" in err[2]) # third line has caret
+ self.assertIn("^", err[2]) # third line has caret
self.assertTrue(err[2].count('\n') == 1) # and no additional newline
self.assertTrue(err[1].find("+") == err[2].find("^")) # in the right place
@@ -64,7 +64,7 @@
IndentationError)
self.assertEqual(len(err), 4)
self.assertEqual(err[1].strip(), "print(2)")
- self.assertTrue("^" in err[2])
+ self.assertIn("^", err[2])
self.assertEqual(err[1].find(")"), err[2].find("^"))
def test_base_exception(self):
@@ -210,7 +210,7 @@
def check_zero_div(self, msg):
lines = msg.splitlines()
self.assertTrue(lines[-3].startswith(' File'))
- self.assertTrue('1/0 # In zero_div' in lines[-2], lines[-2])
+ self.assertIn('1/0 # In zero_div', lines[-2])
self.assertTrue(lines[-1].startswith('ZeroDivisionError'), lines[-1])
def test_simple(self):
@@ -222,7 +222,7 @@
self.assertEquals(len(lines), 4)
self.assertTrue(lines[0].startswith('Traceback'))
self.assertTrue(lines[1].startswith(' File'))
- self.assertTrue('1/0 # Marker' in lines[2])
+ self.assertIn('1/0 # Marker', lines[2])
self.assertTrue(lines[3].startswith('ZeroDivisionError'))
def test_cause(self):
@@ -237,7 +237,7 @@
self.assertEquals(len(blocks), 3)
self.assertEquals(blocks[1], cause_message)
self.check_zero_div(blocks[0])
- self.assertTrue('inner_raise() # Marker' in blocks[2])
+ self.assertIn('inner_raise() # Marker', blocks[2])
def test_context(self):
def inner_raise():
@@ -251,7 +251,7 @@
self.assertEquals(len(blocks), 3)
self.assertEquals(blocks[1], context_message)
self.check_zero_div(blocks[0])
- self.assertTrue('inner_raise() # Marker' in blocks[2])
+ self.assertIn('inner_raise() # Marker', blocks[2])
def test_cause_and_context(self):
# When both a cause and a context are set, only the cause should be
@@ -289,11 +289,11 @@
self.assertEquals(len(blocks), 3)
self.assertEquals(blocks[1], cause_message)
# The first block is the KeyError raised from the ZeroDivisionError
- self.assertTrue('raise KeyError from e' in blocks[0])
- self.assertTrue('1/0' not in blocks[0])
+ self.assertIn('raise KeyError from e', blocks[0])
+ self.assertNotIn('1/0', blocks[0])
# The second block (apart from the boundary) is the ZeroDivisionError
# re-raised from the KeyError
- self.assertTrue('inner_raise() # Marker' in blocks[2])
+ self.assertIn('inner_raise() # Marker', blocks[2])
self.check_zero_div(blocks[2])
Modified: python/branches/py3k-cdecimal/Lib/test/test_types.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_types.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_types.py Thu Jan 21 20:32:23 2010
@@ -434,13 +434,13 @@
result = f.__format__(fmt)
self.assertEqual(len(result), 98)
self.assertEqual(result[-7], '.')
- self.assertTrue(result[:12] in ('112340000000', '112339999999'))
+ self.assertIn(result[:12], ('112340000000', '112339999999'))
f = 1.1234e200
for fmt in 'f', 'F':
result = f.__format__(fmt)
self.assertEqual(len(result), 208)
self.assertEqual(result[-7], '.')
- self.assertTrue(result[:12] in ('112340000000', '112339999999'))
+ self.assertIn(result[:12], ('112340000000', '112339999999'))
test( 1.0, 'e', '1.000000e+00')
Modified: python/branches/py3k-cdecimal/Lib/test/test_unicode.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_unicode.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_unicode.py Thu Jan 21 20:32:23 2010
@@ -436,32 +436,32 @@
def test_contains(self):
# Testing Unicode contains method
- self.assertTrue('a' in 'abdb')
- self.assertTrue('a' in 'bdab')
- self.assertTrue('a' in 'bdaba')
- self.assertTrue('a' in 'bdba')
- self.assertTrue('a' not in 'bdb')
- self.assertTrue('a' in 'bdba')
- self.assertTrue('a' in ('a',1,None))
- self.assertTrue('a' in (1,None,'a'))
- self.assertTrue('a' in ('a',1,None))
- self.assertTrue('a' in (1,None,'a'))
- self.assertTrue('a' not in ('x',1,'y'))
- self.assertTrue('a' not in ('x',1,None))
- self.assertTrue('abcd' not in 'abcxxxx')
- self.assertTrue('ab' in 'abcd')
- self.assertTrue('ab' in 'abc')
- self.assertTrue('ab' in (1,None,'ab'))
- self.assertTrue('' in 'abc')
- self.assertTrue('' in '')
- self.assertTrue('' in 'abc')
- self.assertTrue('\0' not in 'abc')
- self.assertTrue('\0' in '\0abc')
- self.assertTrue('\0' in 'abc\0')
- self.assertTrue('a' in '\0abc')
- self.assertTrue('asdf' in 'asdf')
- self.assertTrue('asdf' not in 'asd')
- self.assertTrue('asdf' not in '')
+ self.assertIn('a', 'abdb')
+ self.assertIn('a', 'bdab')
+ self.assertIn('a', 'bdaba')
+ self.assertIn('a', 'bdba')
+ self.assertNotIn('a', 'bdb')
+ self.assertIn('a', 'bdba')
+ self.assertIn('a', ('a',1,None))
+ self.assertIn('a', (1,None,'a'))
+ self.assertIn('a', ('a',1,None))
+ self.assertIn('a', (1,None,'a'))
+ self.assertNotIn('a', ('x',1,'y'))
+ self.assertNotIn('a', ('x',1,None))
+ self.assertNotIn('abcd', 'abcxxxx')
+ self.assertIn('ab', 'abcd')
+ self.assertIn('ab', 'abc')
+ self.assertIn('ab', (1,None,'ab'))
+ self.assertIn('', 'abc')
+ self.assertIn('', '')
+ self.assertIn('', 'abc')
+ self.assertNotIn('\0', 'abc')
+ self.assertIn('\0', '\0abc')
+ self.assertIn('\0', 'abc\0')
+ self.assertIn('a', '\0abc')
+ self.assertIn('asdf', 'asdf')
+ self.assertNotIn('asdf', 'asd')
+ self.assertNotIn('asdf', '')
self.assertRaises(TypeError, "abc".__contains__)
Modified: python/branches/py3k-cdecimal/Lib/test/test_unicode_file.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_unicode_file.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_unicode_file.py Thu Jan 21 20:32:23 2010
@@ -47,7 +47,7 @@
base = unicodedata.normalize("NFD", base)
file_list = [unicodedata.normalize("NFD", f) for f in file_list]
- self.assertTrue(base in file_list)
+ self.assertIn(base, file_list)
# Do as many "equivalancy' tests as we can - ie, check that although we
# have different types for the filename, they refer to the same file.
Modified: python/branches/py3k-cdecimal/Lib/test/test_unicodedata.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_unicodedata.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_unicodedata.py Thu Jan 21 20:32:23 2010
@@ -220,7 +220,7 @@
self.assertEqual(popen.returncode, 1)
error = "SyntaxError: (unicode error) \\N escapes not supported " \
"(can't load unicodedata module)"
- self.assertTrue(error in popen.stderr.read().decode("ascii"))
+ self.assertIn(error, popen.stderr.read().decode("ascii"))
def test_decimal_numeric_consistent(self):
# Test that decimal and numeric are consistent,
Modified: python/branches/py3k-cdecimal/Lib/test/test_unittest.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_unittest.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_unittest.py Thu Jan 21 20:32:23 2010
@@ -636,7 +636,7 @@
self.assertEqual(list(suite), [])
# audioop should now be loaded, thanks to loadTestsFromName()
- self.assertTrue(module_name in sys.modules)
+ self.assertIn(module_name, sys.modules)
finally:
if module_name in sys.modules:
del sys.modules[module_name]
@@ -1024,7 +1024,7 @@
self.assertEqual(list(suite), [unittest.TestSuite()])
# audioop should now be loaded, thanks to loadTestsFromName()
- self.assertTrue(module_name in sys.modules)
+ self.assertIn(module_name, sys.modules)
finally:
if module_name in sys.modules:
del sys.modules[module_name]
Modified: python/branches/py3k-cdecimal/Lib/test/test_urllib.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_urllib.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_urllib.py Thu Jan 21 20:32:23 2010
@@ -119,6 +119,10 @@
def setUp(self):
# Records changes to env vars
self.env = support.EnvironmentVarGuard()
+ # Delete all proxy related env vars
+ for k in os.environ.keys():
+ if 'proxy' in k.lower():
+ self.env.unset(k)
def tearDown(self):
# Restore all proxy related env vars
Modified: python/branches/py3k-cdecimal/Lib/test/test_urllib2.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_urllib2.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_urllib2.py Thu Jan 21 20:32:23 2010
@@ -21,14 +21,17 @@
# XXX Name hacking to get this to work on Windows.
fname = os.path.abspath(urllib.request.__file__).replace('\\', '/')
- if fname[1:2] == ":":
- fname = fname[2:]
+
# And more hacking to get it to work on MacOS. This assumes
# urllib.pathname2url works, unfortunately...
if os.name == 'mac':
fname = '/' + fname.replace(':', '/')
- file_url = "file://%s" % fname
+ if os.name == 'nt':
+ file_url = "file:///%s" % fname
+ else:
+ file_url = "file://%s" % fname
+
f = urllib.request.urlopen(file_url)
buf = f.read()
@@ -784,8 +787,8 @@
r = MockResponse(200, "OK", {}, "")
newreq = h.do_request_(req)
if data is None: # GET
- self.assertTrue("Content-length" not in req.unredirected_hdrs)
- self.assertTrue("Content-type" not in req.unredirected_hdrs)
+ self.assertNotIn("Content-length", req.unredirected_hdrs)
+ self.assertNotIn("Content-type", req.unredirected_hdrs)
else: # POST
self.assertEqual(req.unredirected_hdrs["Content-length"], "0")
self.assertEqual(req.unredirected_hdrs["Content-type"],
@@ -904,13 +907,13 @@
# now it's a GET, there should not be headers regarding content
# (possibly dragged from before being a POST)
headers = [x.lower() for x in o.req.headers]
- self.assertTrue("content-length" not in headers)
- self.assertTrue("content-type" not in headers)
+ self.assertNotIn("content-length", headers)
+ self.assertNotIn("content-type", headers)
self.assertEqual(o.req.headers["Nonsense"],
"viking=withhold")
- self.assertTrue("Spam" not in o.req.headers)
- self.assertTrue("Spam" not in o.req.unredirected_hdrs)
+ self.assertNotIn("Spam", o.req.headers)
+ self.assertNotIn("Spam", o.req.unredirected_hdrs)
# loop detection
req = Request(from_url)
Modified: python/branches/py3k-cdecimal/Lib/test/test_userdict.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_userdict.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_userdict.py Thu Jan 21 20:32:23 2010
@@ -95,7 +95,7 @@
# Test "in".
for i in u2.keys():
- self.assertTrue(i in u2)
+ self.assertIn(i, u2)
self.assertEqual(i in u1, i in d1)
self.assertEqual(i in u0, i in d0)
@@ -122,7 +122,7 @@
# Test setdefault
t = collections.UserDict()
self.assertEqual(t.setdefault("x", 42), 42)
- self.assertTrue("x" in t)
+ self.assertIn("x", t)
self.assertEqual(t.setdefault("x", 23), 42)
# Test pop
@@ -152,8 +152,8 @@
d = D({1: 2, 3: 4})
self.assertEqual(d[1], 2)
self.assertEqual(d[3], 4)
- self.assertTrue(2 not in d)
- self.assertTrue(2 not in d.keys())
+ self.assertNotIn(2, d)
+ self.assertNotIn(2, d.keys())
self.assertEqual(d[2], 42)
class E(collections.UserDict):
def __missing__(self, key):
Modified: python/branches/py3k-cdecimal/Lib/test/test_warnings.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_warnings.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_warnings.py Thu Jan 21 20:32:23 2010
@@ -483,7 +483,7 @@
with support.captured_output('stderr') as stream:
self.module.warn(text)
result = stream.getvalue()
- self.assertTrue(text in result)
+ self.assertIn(text, result)
def test_showwarning_not_callable(self):
with original_warnings.catch_warnings(module=self.module):
Modified: python/branches/py3k-cdecimal/Lib/test/test_wave.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_wave.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_wave.py Thu Jan 21 20:32:23 2010
@@ -1,6 +1,7 @@
from test.support import TESTFN, run_unittest
import os
import wave
+import struct
import unittest
nchannels = 2
@@ -38,6 +39,16 @@
self.assertEqual(nframes, self.f.getnframes())
self.assertEqual(self.f.readframes(nframes), output)
+ def test_issue7681(self):
+ self.f = wave.open(TESTFN, 'wb')
+ self.f.setnchannels(nchannels)
+ self.f.setsampwidth(sampwidth)
+ self.f.setframerate(framerate)
+ # Don't call setnframes, make _write_header divide to figure it out
+ output = b'\0' * nframes * nchannels * sampwidth
+ self.f.writeframes(output)
+
+
def test_main():
run_unittest(TestWave)
Modified: python/branches/py3k-cdecimal/Lib/test/test_weakref.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_weakref.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_weakref.py Thu Jan 21 20:32:23 2010
@@ -4,6 +4,8 @@
import collections
import weakref
import operator
+import contextlib
+import copy
from test import support
@@ -191,7 +193,7 @@
def __bytes__(self):
return b"bytes"
instance = C()
- self.assertTrue("__bytes__" in dir(weakref.proxy(instance)))
+ self.assertIn("__bytes__", dir(weakref.proxy(instance)))
self.assertEqual(bytes(weakref.proxy(instance)), b"bytes")
def test_proxy_index(self):
@@ -713,8 +715,8 @@
refs = weakref.getweakrefs(o)
self.assertEqual(len(refs), 3)
self.assertTrue(r2 is refs[0])
- self.assertTrue(r1 in refs[1:])
- self.assertTrue(r3 in refs[1:])
+ self.assertIn(r1, refs[1:])
+ self.assertIn(r3, refs[1:])
def test_subclass_refs_dont_conflate_callbacks(self):
class MyRef(weakref.ref):
@@ -724,8 +726,8 @@
r2 = MyRef(o, str)
self.assertTrue(r1 is not r2)
refs = weakref.getweakrefs(o)
- self.assertTrue(r1 in refs)
- self.assertTrue(r2 in refs)
+ self.assertIn(r1, refs)
+ self.assertIn(r2, refs)
def test_subclass_refs_with_slots(self):
class MyRef(weakref.ref):
@@ -788,6 +790,10 @@
self.arg = arg
def __repr__(self):
return "<Object %r>" % self.arg
+ def __eq__(self, other):
+ if isinstance(other, Object):
+ return self.arg == other.arg
+ return NotImplemented
def __lt__(self, other):
if isinstance(other, Object):
return self.arg < other.arg
@@ -854,8 +860,8 @@
"deleting the keys did not clear the dictionary")
o = Object(42)
dict[o] = "What is the meaning of the universe?"
- self.assertTrue(o in dict)
- self.assertTrue(34 not in dict)
+ self.assertIn(o, dict)
+ self.assertNotIn(34, dict)
def test_weak_keyed_iters(self):
dict, objects = self.make_weak_keyed_dict()
@@ -867,8 +873,8 @@
objects2 = list(objects)
for wr in refs:
ob = wr()
- self.assertTrue(ob in dict)
- self.assertTrue(ob in dict)
+ self.assertIn(ob, dict)
+ self.assertIn(ob, dict)
self.assertEqual(ob.arg, dict[ob])
objects2.remove(ob)
self.assertEqual(len(objects2), 0)
@@ -878,8 +884,8 @@
self.assertEqual(len(list(dict.keyrefs())), len(objects))
for wr in dict.keyrefs():
ob = wr()
- self.assertTrue(ob in dict)
- self.assertTrue(ob in dict)
+ self.assertIn(ob, dict)
+ self.assertIn(ob, dict)
self.assertEqual(ob.arg, dict[ob])
objects2.remove(ob)
self.assertEqual(len(objects2), 0)
@@ -935,6 +941,87 @@
self.assertFalse(values,
"itervalues() did not touch all values")
+ def check_weak_destroy_while_iterating(self, dict, objects, iter_name):
+ n = len(dict)
+ it = iter(getattr(dict, iter_name)())
+ next(it) # Trigger internal iteration
+ # Destroy an object
+ del objects[-1]
+ gc.collect() # just in case
+ # We have removed either the first consumed object, or another one
+ self.assertIn(len(list(it)), [len(objects), len(objects) - 1])
+ del it
+ # The removal has been committed
+ self.assertEqual(len(dict), n - 1)
+
+ def check_weak_destroy_and_mutate_while_iterating(self, dict, testcontext):
+ # Check that we can explicitly mutate the weak dict without
+ # interfering with delayed removal.
+ # `testcontext` should create an iterator, destroy one of the
+ # weakref'ed objects and then return a new key/value pair corresponding
+ # to the destroyed object.
+ with testcontext() as (k, v):
+ self.assertFalse(k in dict)
+ with testcontext() as (k, v):
+ self.assertRaises(KeyError, dict.__delitem__, k)
+ self.assertFalse(k in dict)
+ with testcontext() as (k, v):
+ self.assertRaises(KeyError, dict.pop, k)
+ self.assertFalse(k in dict)
+ with testcontext() as (k, v):
+ dict[k] = v
+ self.assertEqual(dict[k], v)
+ ddict = copy.copy(dict)
+ with testcontext() as (k, v):
+ dict.update(ddict)
+ self.assertEqual(dict, ddict)
+ with testcontext() as (k, v):
+ dict.clear()
+ self.assertEqual(len(dict), 0)
+
+ def test_weak_keys_destroy_while_iterating(self):
+ # Issue #7105: iterators shouldn't crash when a key is implicitly removed
+ dict, objects = self.make_weak_keyed_dict()
+ self.check_weak_destroy_while_iterating(dict, objects, 'keys')
+ self.check_weak_destroy_while_iterating(dict, objects, 'items')
+ self.check_weak_destroy_while_iterating(dict, objects, 'values')
+ self.check_weak_destroy_while_iterating(dict, objects, 'keyrefs')
+ dict, objects = self.make_weak_keyed_dict()
+ @contextlib.contextmanager
+ def testcontext():
+ try:
+ it = iter(dict.items())
+ next(it)
+ # Schedule a key/value for removal and recreate it
+ v = objects.pop().arg
+ gc.collect() # just in case
+ yield Object(v), v
+ finally:
+ it = None # should commit all removals
+ self.check_weak_destroy_and_mutate_while_iterating(dict, testcontext)
+
+ def test_weak_values_destroy_while_iterating(self):
+ # Issue #7105: iterators shouldn't crash when a key is implicitly removed
+ dict, objects = self.make_weak_valued_dict()
+ self.check_weak_destroy_while_iterating(dict, objects, 'keys')
+ self.check_weak_destroy_while_iterating(dict, objects, 'items')
+ self.check_weak_destroy_while_iterating(dict, objects, 'values')
+ self.check_weak_destroy_while_iterating(dict, objects, 'itervaluerefs')
+ self.check_weak_destroy_while_iterating(dict, objects, 'valuerefs')
+ dict, objects = self.make_weak_valued_dict()
+ @contextlib.contextmanager
+ def testcontext():
+ try:
+ it = iter(dict.items())
+ next(it)
+ # Schedule a key/value for removal and recreate it
+ k = objects.pop().arg
+ gc.collect() # just in case
+ yield k, Object(k)
+ finally:
+ it = None # should commit all removals
+ self.check_weak_destroy_and_mutate_while_iterating(dict, testcontext)
+
def test_make_weak_keyed_dict_from_dict(self):
o = Object(3)
dict = weakref.WeakKeyDictionary({o:364})
@@ -1004,13 +1091,13 @@
weakdict = klass()
o = weakdict.setdefault(key, value1)
self.assertTrue(o is value1)
- self.assertTrue(key in weakdict)
+ self.assertIn(key, weakdict)
self.assertTrue(weakdict.get(key) is value1)
self.assertTrue(weakdict[key] is value1)
o = weakdict.setdefault(key, value2)
self.assertTrue(o is value1)
- self.assertTrue(key in weakdict)
+ self.assertIn(key, weakdict)
self.assertTrue(weakdict.get(key) is value1)
self.assertTrue(weakdict[key] is value1)
Modified: python/branches/py3k-cdecimal/Lib/test/test_weakset.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_weakset.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_weakset.py Thu Jan 21 20:32:23 2010
@@ -10,6 +10,8 @@
import warnings
import collections
from collections import UserString as ustr
+import gc
+import contextlib
class Foo:
@@ -49,9 +51,9 @@
for c in self.letters:
self.assertEqual(c in self.s, c in self.d)
self.assertRaises(TypeError, self.s.__contains__, [[]])
- self.assertTrue(self.obj in self.fs)
+ self.assertIn(self.obj, self.fs)
del self.obj
- self.assertTrue(ustr('F') not in self.fs)
+ self.assertNotIn(ustr('F'), self.fs)
def test_union(self):
u = self.s.union(self.items2)
@@ -148,7 +150,7 @@
s=H()
f=set()
f.add(s)
- self.assertTrue(s in f)
+ self.assertIn(s, f)
f.remove(s)
f.add(s)
f.discard(s)
@@ -183,7 +185,7 @@
def test_add(self):
x = ustr('Q')
self.s.add(x)
- self.assertTrue(x in self.s)
+ self.assertIn(x, self.s)
dup = self.s.copy()
self.s.add(x)
self.assertEqual(self.s, dup)
@@ -196,66 +198,66 @@
def test_remove(self):
x = ustr('a')
self.s.remove(x)
- self.assertTrue(x not in self.s)
+ self.assertNotIn(x, self.s)
self.assertRaises(KeyError, self.s.remove, x)
self.assertRaises(TypeError, self.s.remove, [])
def test_discard(self):
a, q = ustr('a'), ustr('Q')
self.s.discard(a)
- self.assertTrue(a not in self.s)
+ self.assertNotIn(a, self.s)
self.s.discard(q)
self.assertRaises(TypeError, self.s.discard, [])
def test_pop(self):
for i in range(len(self.s)):
elem = self.s.pop()
- self.assertTrue(elem not in self.s)
+ self.assertNotIn(elem, self.s)
self.assertRaises(KeyError, self.s.pop)
def test_update(self):
retval = self.s.update(self.items2)
self.assertEqual(retval, None)
for c in (self.items + self.items2):
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
self.assertRaises(TypeError, self.s.update, [[]])
def test_update_set(self):
self.s.update(set(self.items2))
for c in (self.items + self.items2):
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
def test_ior(self):
self.s |= set(self.items2)
for c in (self.items + self.items2):
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
def test_intersection_update(self):
retval = self.s.intersection_update(self.items2)
self.assertEqual(retval, None)
for c in (self.items + self.items2):
if c in self.items2 and c in self.items:
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
else:
- self.assertTrue(c not in self.s)
+ self.assertNotIn(c, self.s)
self.assertRaises(TypeError, self.s.intersection_update, [[]])
def test_iand(self):
self.s &= set(self.items2)
for c in (self.items + self.items2):
if c in self.items2 and c in self.items:
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
else:
- self.assertTrue(c not in self.s)
+ self.assertNotIn(c, self.s)
def test_difference_update(self):
retval = self.s.difference_update(self.items2)
self.assertEqual(retval, None)
for c in (self.items + self.items2):
if c in self.items and c not in self.items2:
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
else:
- self.assertTrue(c not in self.s)
+ self.assertNotIn(c, self.s)
self.assertRaises(TypeError, self.s.difference_update, [[]])
self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]])
@@ -263,27 +265,27 @@
self.s -= set(self.items2)
for c in (self.items + self.items2):
if c in self.items and c not in self.items2:
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
else:
- self.assertTrue(c not in self.s)
+ self.assertNotIn(c, self.s)
def test_symmetric_difference_update(self):
retval = self.s.symmetric_difference_update(self.items2)
self.assertEqual(retval, None)
for c in (self.items + self.items2):
if (c in self.items) ^ (c in self.items2):
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
else:
- self.assertTrue(c not in self.s)
+ self.assertNotIn(c, self.s)
self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]])
def test_ixor(self):
self.s ^= set(self.items2)
for c in (self.items + self.items2):
if (c in self.items) ^ (c in self.items2):
- self.assertTrue(c in self.s)
+ self.assertIn(c, self.s)
else:
- self.assertTrue(c not in self.s)
+ self.assertNotIn(c, self.s)
def test_inplace_on_self(self):
t = self.s.copy()
@@ -307,6 +309,54 @@
self.assertFalse(self.s == WeakSet([Foo]))
self.assertFalse(self.s == 1)
+ def test_weak_destroy_while_iterating(self):
+ # Issue #7105: iterators shouldn't crash when a key is implicitly removed
+ # Create new items to be sure no-one else holds a reference
+ items = [ustr(c) for c in ('a', 'b', 'c')]
+ s = WeakSet(items)
+ it = iter(s)
+ next(it) # Trigger internal iteration
+ # Destroy an item
+ del items[-1]
+ gc.collect() # just in case
+ # We have removed either the first consumed items, or another one
+ self.assertIn(len(list(it)), [len(items), len(items) - 1])
+ del it
+ # The removal has been committed
+ self.assertEqual(len(s), len(items))
+
+ def test_weak_destroy_and_mutate_while_iterating(self):
+ # Issue #7105: iterators shouldn't crash when a key is implicitly removed
+ items = [ustr(c) for c in string.ascii_letters]
+ s = WeakSet(items)
+ @contextlib.contextmanager
+ def testcontext():
+ try:
+ it = iter(s)
+ next(it)
+ # Schedule an item for removal and recreate it
+ u = ustr(str(items.pop()))
+ gc.collect() # just in case
+ yield u
+ finally:
+ it = None # should commit all removals
+
+ with testcontext() as u:
+ self.assertFalse(u in s)
+ with testcontext() as u:
+ self.assertRaises(KeyError, s.remove, u)
+ self.assertFalse(u in s)
+ with testcontext() as u:
+ s.add(u)
+ self.assertIn(u, s)
+ t = s.copy()
+ with testcontext() as u:
+ s.update(t)
+ self.assertEqual(len(s), len(t))
+ with testcontext() as u:
+ s.clear()
+ self.assertEqual(len(s), 0)
+
def test_main(verbose=None):
support.run_unittest(TestWeakSet)
Modified: python/branches/py3k-cdecimal/Lib/test/test_wsgiref.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_wsgiref.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_wsgiref.py Thu Jan 21 20:32:23 2010
@@ -440,7 +440,7 @@
h.get("content-disposition"))
del h['content-disposition']
- self.assertTrue(b'content-disposition' not in h)
+ self.assertNotIn(b'content-disposition', h)
class ErrorHandler(BaseCGIHandler):
@@ -493,7 +493,7 @@
if k not in empty:
self.assertEqual(env[k],v)
for k,v in empty.items():
- self.assertTrue(k in env)
+ self.assertIn(k, env)
def testEnviron(self):
h = TestHandler(X="Y")
@@ -506,7 +506,7 @@
h = BaseCGIHandler(None,None,None,{})
h.setup_environ()
for key in 'wsgi.url_scheme', 'wsgi.input', 'wsgi.errors':
- self.assertTrue(key in h.environ)
+ self.assertIn(key, h.environ)
def testScheme(self):
h=TestHandler(HTTPS="on"); h.setup_environ()
@@ -593,7 +593,7 @@
"\r\n%s" % (h.error_status,len(h.error_body),h.error_body)
).encode("iso-8859-1"))
- self.assertTrue("AssertionError" in h.stderr.getvalue())
+ self.assertIn("AssertionError", h.stderr.getvalue())
def testErrorAfterOutput(self):
MSG = "Some output has been sent"
@@ -606,7 +606,7 @@
self.assertEqual(h.stdout.getvalue(),
("Status: 200 OK\r\n"
"\r\n"+MSG).encode("iso-8859-1"))
- self.assertTrue("AssertionError" in h.stderr.getvalue())
+ self.assertIn("AssertionError", h.stderr.getvalue())
def testHeaderFormats(self):
Modified: python/branches/py3k-cdecimal/Lib/test/test_zipfile.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_zipfile.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_zipfile.py Thu Jan 21 20:32:23 2010
@@ -63,9 +63,9 @@
lines = directory.splitlines()
self.assertEqual(len(lines), 4) # Number of files + header
- self.assertTrue('File Name' in lines[0])
- self.assertTrue('Modified' in lines[0])
- self.assertTrue('Size' in lines[0])
+ self.assertIn('File Name', lines[0])
+ self.assertIn('Modified', lines[0])
+ self.assertIn('Size', lines[0])
fn, date, time_, size = lines[1].split()
self.assertEqual(fn, 'another.name')
@@ -76,17 +76,17 @@
# Check the namelist
names = zipfp.namelist()
self.assertEqual(len(names), 3)
- self.assertTrue(TESTFN in names)
- self.assertTrue("another.name" in names)
- self.assertTrue("strfile" in names)
+ self.assertIn(TESTFN, names)
+ self.assertIn("another.name", names)
+ self.assertIn("strfile", names)
# Check infolist
infos = zipfp.infolist()
names = [i.filename for i in infos]
self.assertEqual(len(names), 3)
- self.assertTrue(TESTFN in names)
- self.assertTrue("another.name" in names)
- self.assertTrue("strfile" in names)
+ self.assertIn(TESTFN, names)
+ self.assertIn("another.name", names)
+ self.assertIn("strfile", names)
for i in infos:
self.assertEqual(i.file_size, len(self.data))
@@ -459,9 +459,9 @@
lines = directory.splitlines()
self.assertEqual(len(lines), 4) # Number of files + header
- self.assertTrue('File Name' in lines[0])
- self.assertTrue('Modified' in lines[0])
- self.assertTrue('Size' in lines[0])
+ self.assertIn('File Name', lines[0])
+ self.assertIn('Modified', lines[0])
+ self.assertIn('Size', lines[0])
fn, date, time_, size = lines[1].split()
self.assertEqual(fn, 'another.name')
@@ -472,17 +472,17 @@
# Check the namelist
names = zipfp.namelist()
self.assertEqual(len(names), 3)
- self.assertTrue(TESTFN in names)
- self.assertTrue("another.name" in names)
- self.assertTrue("strfile" in names)
+ self.assertIn(TESTFN, names)
+ self.assertIn("another.name", names)
+ self.assertIn("strfile", names)
# Check infolist
infos = zipfp.infolist()
names = [i.filename for i in infos]
self.assertEqual(len(names), 3)
- self.assertTrue(TESTFN in names)
- self.assertTrue("another.name" in names)
- self.assertTrue("strfile" in names)
+ self.assertIn(TESTFN, names)
+ self.assertIn("another.name", names)
+ self.assertIn("strfile", names)
for i in infos:
self.assertEqual(i.file_size, len(self.data))
@@ -528,7 +528,7 @@
zipfp.writepy(fn)
bn = os.path.basename(fn)
- self.assertTrue(bn not in zipfp.namelist())
+ self.assertNotIn(bn, zipfp.namelist())
self.assertTrue(bn + 'o' in zipfp.namelist() or
bn + 'c' in zipfp.namelist())
@@ -540,7 +540,7 @@
zipfp.writepy(fn, "testpackage")
bn = "%s/%s" % ("testpackage", os.path.basename(fn))
- self.assertTrue(bn not in zipfp.namelist())
+ self.assertNotIn(bn, zipfp.namelist())
self.assertTrue(bn + 'o' in zipfp.namelist() or
bn + 'c' in zipfp.namelist())
@@ -577,7 +577,7 @@
names = zipfp.namelist()
self.assertTrue('mod1.pyc' in names or 'mod1.pyo' in names)
self.assertTrue('mod2.pyc' in names or 'mod2.pyo' in names)
- self.assertTrue('mod2.txt' not in names)
+ self.assertNotIn('mod2.txt', names)
finally:
shutil.rmtree(TESTFN2)
Modified: python/branches/py3k-cdecimal/Lib/test/test_zipimport.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_zipimport.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_zipimport.py Thu Jan 21 20:32:23 2010
@@ -294,7 +294,7 @@
z.close()
zi = zipimport.zipimporter(TEMP_ZIP)
self.assertEquals(data, zi.get_data(name))
- self.assertTrue('zipimporter object' in repr(zi))
+ self.assertIn('zipimporter object', repr(zi))
finally:
z.close()
os.remove(TEMP_ZIP)
Modified: python/branches/py3k-cdecimal/Lib/test/test_zipimport_support.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_zipimport_support.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_zipimport_support.py Thu Jan 21 20:32:23 2010
@@ -185,7 +185,7 @@
print ("Expected line", expected)
print ("Got stdout:")
print (data)
- self.assertTrue(expected.encode('utf-8') in data)
+ self.assertIn(expected.encode('utf-8'), data)
zip_name, run_name = make_zip_script(d, "test_zip",
script_name, '__main__.py')
exit_code, data = run_python(zip_name)
@@ -194,7 +194,7 @@
print ("Expected line", expected)
print ("Got stdout:")
print (data)
- self.assertTrue(expected.encode('utf-8') in data)
+ self.assertIn(expected.encode('utf-8'), data)
def test_pdb_issue4201(self):
test_src = textwrap.dedent("""\
@@ -209,13 +209,13 @@
p = spawn_python(script_name)
p.stdin.write(b'l\n')
data = kill_python(p)
- self.assertTrue(script_name.encode('utf-8') in data)
+ self.assertIn(script_name.encode('utf-8'), data)
zip_name, run_name = make_zip_script(d, "test_zip",
script_name, '__main__.py')
p = spawn_python(zip_name)
p.stdin.write(b'l\n')
data = kill_python(p)
- self.assertTrue(run_name.encode('utf-8') in data)
+ self.assertIn(run_name.encode('utf-8'), data)
def test_main():
Modified: python/branches/py3k-cdecimal/Lib/turtle.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/turtle.py (original)
+++ python/branches/py3k-cdecimal/Lib/turtle.py Thu Jan 21 20:32:23 2010
@@ -2,7 +2,7 @@
# turtle.py: a Tkinter based turtle graphics module for Python
# Version 1.1b - 4. 5. 2009
#
-# Copyright (C) 2006 - 2009 Gregor Lingl
+# Copyright (C) 2006 - 2010 Gregor Lingl
# email: glingl at aon.at
#
# This software is provided 'as-is', without any express or implied
Modified: python/branches/py3k-cdecimal/Lib/unittest/__init__.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/unittest/__init__.py (original)
+++ python/branches/py3k-cdecimal/Lib/unittest/__init__.py Thu Jan 21 20:32:23 2010
@@ -27,7 +27,7 @@
http://docs.python.org/library/unittest.html
Copyright (c) 1999-2003 Steve Purcell
-Copyright (c) 2003-2009 Python Software Foundation
+Copyright (c) 2003-2010 Python Software Foundation
This module is free software, and you may redistribute it and/or modify
it under the same terms as Python itself, so long as this copyright message
and disclaimer are retained in their original form.
Modified: python/branches/py3k-cdecimal/Lib/wave.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/wave.py (original)
+++ python/branches/py3k-cdecimal/Lib/wave.py Thu Jan 21 20:32:23 2010
@@ -240,7 +240,7 @@
data = array.array(_array_fmts[self._sampwidth])
nitems = nframes * self._nchannels
if nitems * self._sampwidth > chunk.chunksize - chunk.size_read:
- nitems = (chunk.chunksize - chunk.size_read) / self._sampwidth
+ nitems = (chunk.chunksize - chunk.size_read) // self._sampwidth
data.fromfile(chunk.file.file, nitems)
# "tell" data chunk how much was read
chunk.size_read = chunk.size_read + nitems * self._sampwidth
@@ -461,7 +461,7 @@
def _write_header(self, initlength):
self._file.write(b'RIFF')
if not self._nframes:
- self._nframes = initlength / (self._nchannels * self._sampwidth)
+ self._nframes = initlength // (self._nchannels * self._sampwidth)
self._datalength = self._nframes * self._nchannels * self._sampwidth
self._form_length_pos = self._file.tell()
self._file.write(struct.pack('<l4s4slhhllhh4s',
Modified: python/branches/py3k-cdecimal/Lib/weakref.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/weakref.py (original)
+++ python/branches/py3k-cdecimal/Lib/weakref.py Thu Jan 21 20:32:23 2010
@@ -18,7 +18,7 @@
ProxyType,
ReferenceType)
-from _weakrefset import WeakSet
+from _weakrefset import WeakSet, _IterationGuard
import collections # Import after _weakref to avoid circular import.
@@ -46,11 +46,25 @@
def remove(wr, selfref=ref(self)):
self = selfref()
if self is not None:
- del self.data[wr.key]
+ if self._iterating:
+ self._pending_removals.append(wr.key)
+ else:
+ del self.data[wr.key]
self._remove = remove
+ # A list of keys to be removed
+ self._pending_removals = []
+ self._iterating = set()
self.data = d = {}
self.update(*args, **kw)
+ def _commit_removals(self):
+ l = self._pending_removals
+ d = self.data
+ # We shouldn't encounter any KeyError, because this method should
+ # always be called *before* mutating the dict.
+ while l:
+ del d[l.pop()]
+
def __getitem__(self, key):
o = self.data[key]()
if o is None:
@@ -59,6 +73,8 @@
return o
def __delitem__(self, key):
+ if self._pending_removals:
+ self._commit_removals()
del self.data[key]
def __len__(self):
@@ -75,6 +91,8 @@
return "<WeakValueDictionary at %s>" % id(self)
def __setitem__(self, key, value):
+ if self._pending_removals:
+ self._commit_removals()
self.data[key] = KeyedRef(value, self._remove, key)
def copy(self):
@@ -110,24 +128,19 @@
return o
def items(self):
- L = []
- for key, wr in self.data.items():
- o = wr()
- if o is not None:
- L.append((key, o))
- return L
-
- def items(self):
- for wr in self.data.values():
- value = wr()
- if value is not None:
- yield wr.key, value
+ with _IterationGuard(self):
+ for k, wr in self.data.items():
+ v = wr()
+ if v is not None:
+ yield k, v
def keys(self):
- return iter(self.data.keys())
+ with _IterationGuard(self):
+ for k, wr in self.data.items():
+ if wr() is not None:
+ yield k
- def __iter__(self):
- return iter(self.data.keys())
+ __iter__ = keys
def itervaluerefs(self):
"""Return an iterator that yields the weak references to the values.
@@ -139,15 +152,20 @@
keep the values around longer than needed.
"""
- return self.data.values()
+ with _IterationGuard(self):
+ for wr in self.data.values():
+ yield wr
def values(self):
- for wr in self.data.values():
- obj = wr()
- if obj is not None:
- yield obj
+ with _IterationGuard(self):
+ for wr in self.data.values():
+ obj = wr()
+ if obj is not None:
+ yield obj
def popitem(self):
+ if self._pending_removals:
+ self._commit_removals()
while 1:
key, wr = self.data.popitem()
o = wr()
@@ -155,6 +173,8 @@
return key, o
def pop(self, key, *args):
+ if self._pending_removals:
+ self._commit_removals()
try:
o = self.data.pop(key)()
except KeyError:
@@ -170,12 +190,16 @@
try:
wr = self.data[key]
except KeyError:
+ if self._pending_removals:
+ self._commit_removals()
self.data[key] = KeyedRef(default, self._remove, key)
return default
else:
return wr()
def update(self, dict=None, **kwargs):
+ if self._pending_removals:
+ self._commit_removals()
d = self.data
if dict is not None:
if not hasattr(dict, "items"):
@@ -195,7 +219,7 @@
keep the values around longer than needed.
"""
- return self.data.values()
+ return list(self.data.values())
class KeyedRef(ref):
@@ -235,9 +259,29 @@
def remove(k, selfref=ref(self)):
self = selfref()
if self is not None:
- del self.data[k]
+ if self._iterating:
+ self._pending_removals.append(k)
+ else:
+ del self.data[k]
self._remove = remove
- if dict is not None: self.update(dict)
+ # A list of dead weakrefs (keys to be removed)
+ self._pending_removals = []
+ self._iterating = set()
+ if dict is not None:
+ self.update(dict)
+
+ def _commit_removals(self):
+ # NOTE: We don't need to call this method before mutating the dict,
+ # because a dead weakref never compares equal to a live weakref,
+ # even if they happened to refer to equal objects.
+ # However, it means keys may already have been removed.
+ l = self._pending_removals
+ d = self.data
+ while l:
+ try:
+ del d[l.pop()]
+ except KeyError:
+ pass
def __delitem__(self, key):
del self.data[ref(key)]
@@ -284,34 +328,26 @@
return wr in self.data
def items(self):
- for wr, value in self.data.items():
- key = wr()
- if key is not None:
- yield key, value
-
- def keyrefs(self):
- """Return an iterator that yields the weak references to the keys.
-
- The references are not guaranteed to be 'live' at the time
- they are used, so the result of calling the references needs
- to be checked before being used. This can be used to avoid
- creating references that will cause the garbage collector to
- keep the keys around longer than needed.
-
- """
- return self.data.keys()
+ with _IterationGuard(self):
+ for wr, value in self.data.items():
+ key = wr()
+ if key is not None:
+ yield key, value
def keys(self):
- for wr in self.data.keys():
- obj = wr()
- if obj is not None:
- yield obj
+ with _IterationGuard(self):
+ for wr in self.data:
+ obj = wr()
+ if obj is not None:
+ yield obj
- def __iter__(self):
- return iter(self.keys())
+ __iter__ = keys
def values(self):
- return iter(self.data.values())
+ with _IterationGuard(self):
+ for wr, value in self.data.items():
+ if wr() is not None:
+ yield value
def keyrefs(self):
"""Return a list of weak references to the keys.
@@ -323,7 +359,7 @@
keep the keys around longer than needed.
"""
- return self.data.keys()
+ return list(self.data)
def popitem(self):
while 1:
Modified: python/branches/py3k-cdecimal/Mac/Resources/app/Info.plist.in
==============================================================================
--- python/branches/py3k-cdecimal/Mac/Resources/app/Info.plist.in (original)
+++ python/branches/py3k-cdecimal/Mac/Resources/app/Info.plist.in Thu Jan 21 20:32:23 2010
@@ -20,7 +20,7 @@
<key>CFBundleExecutable</key>
<string>Python</string>
<key>CFBundleGetInfoString</key>
- <string>%version%, (c) 2004-2009 Python Software Foundation.</string>
+ <string>%version%, (c) 2004-2010 Python Software Foundation.</string>
<key>CFBundleHelpBookFolder</key>
<array>
<string>Documentation</string>
@@ -37,7 +37,7 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
- <string>%version%, (c) 2004-2009 Python Software Foundation.</string>
+ <string>%version%, (c) 2004-2010 Python Software Foundation.</string>
<key>CFBundleName</key>
<string>Python</string>
<key>CFBundlePackageType</key>
Modified: python/branches/py3k-cdecimal/Makefile.pre.in
==============================================================================
--- python/branches/py3k-cdecimal/Makefile.pre.in (original)
+++ python/branches/py3k-cdecimal/Makefile.pre.in Thu Jan 21 20:32:23 2010
@@ -582,6 +582,7 @@
$(srcdir)/Objects/stringlib/fastsearch.h \
$(srcdir)/Objects/stringlib/find.h \
$(srcdir)/Objects/stringlib/partition.h \
+ $(srcdir)/Objects/stringlib/split.h \
$(srcdir)/Objects/stringlib/stringdefs.h \
$(srcdir)/Objects/stringlib/string_format.h \
$(srcdir)/Objects/stringlib/transmogrify.h \
Modified: python/branches/py3k-cdecimal/Misc/ACKS
==============================================================================
--- python/branches/py3k-cdecimal/Misc/ACKS (original)
+++ python/branches/py3k-cdecimal/Misc/ACKS Thu Jan 21 20:32:23 2010
@@ -164,6 +164,7 @@
Drew Csillag
John Cugini
Tom Culliton
+Brian Curtin
Lisandro Dalcin
Andrew Dalke
Lars Damerow
Modified: python/branches/py3k-cdecimal/Misc/NEWS
==============================================================================
--- python/branches/py3k-cdecimal/Misc/NEWS (original)
+++ python/branches/py3k-cdecimal/Misc/NEWS Thu Jan 21 20:32:23 2010
@@ -12,6 +12,31 @@
Core and Builtins
-----------------
+- Issue #7561: Operations on empty bytearrays (such as `int(bytearray())`)
+ could crash in many places because of the PyByteArray_AS_STRING() macro
+ returning NULL. The macro now returns a statically allocated empty
+ string instead.
+
+- Issue #6690: Optimize the bytecode for expressions such as `x in {1, 2, 3}`,
+ where the right hand operand is a set of constants, by turning the set into
+ a frozenset and pre-building it as a constant. The comparison operation
+ is made against the constant instead of building a new set each time it is
+ executed (a similar optimization already existed which turned a list of
+ constants into a pre-built tuple). Patch and additional tests by Dave
+ Malcolm.
+
+- Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
+ methods of bytes, bytearray and unicode objects by using a common
+ implementation based on stringlib's fast search. Patch by Florent Xicluna.
+
+- Issue #7632: Fix various str -> float conversion bugs present in 2.7
+ alpha 2, including: (1) a serious 'wrong output' bug that could
+ occur for long (> 40 digit) input strings, (2) a crash in dtoa.c
+ that occurred in debug builds when parsing certain long numeric
+ strings corresponding to subnormal values, (3) a memory leak for
+ some values large enough to cause overflow, and (4) a number of
+ flaws that could lead to incorrectly rounded results.
+
- The __complex__ method is now looked up on the class of instances to make it
consistent with other special methods.
@@ -149,9 +174,19 @@
- Issue #6687: PyBytes_FromObject() no longer accepts an integer as its
argument to construct a null-initialized bytes object.
+- Issue #1023290: Add from_bytes() and to_bytes() methods to integers.
+ These methods allow the conversion of integers to bytes, and vice-versa.
+
+- Issue #7382: Fix bug in bytes.__getnewargs__ that prevented bytes
+ instances from being copied with copy.copy(), and bytes subclasses
+ from being pickled properly.
+
C-API
-----
+- Make PyUnicode_CompareWithASCIIString return not equal if the Python string
+ has '\0' at the end.
+
- Issue #5080: The argument parsing functions PyArg_ParseTuple,
PyArg_ParseTupleAndKeywords, PyArg_VaParse,
PyArg_VaParseTupleAndKeywords and PyArg_Parse now raise a
@@ -194,6 +229,41 @@
Library
-------
+- Issue #7561: Fix crashes when using bytearray objects with the posix
+ module.
+
+- Issue #1670765: Prevent email.generator.Generator from re-wrapping
+ headers in multipart/signed MIME parts, which fixes one of the sources of
+ invalid modifications to such parts by Generator.
+
+- Issue #7703: Add support for the new buffer API to `binascii.a2bhqx`.
+ Patch by Florent Xicluna, along with some additional tests.
+
+- Issue #7701: Fix crash in binascii.b2a_uu() in debug mode when given a
+ 1-byte argument. Patch by Victor Stinner.
+
+- Issue #3299: Fix possible crash in the _sre module when given bad
+ argument values in debug mode. Patch by Victor Stinner.
+
+- Issue #2846: Add support for gzip.GzipFile reading zero-padded files.
+ Patch by Brian Curtin.
+
+- Issue #7681: Use floor division in appropiate places in the wave module.
+
+- Issue #5372: Drop the reuse of .o files in Distutils' ccompiler (since
+ Extension extra options may change the output without changing the .c
+ file). Initial patch by Collin Winter.
+
+- Issue #7617: Make sure distutils.unixccompiler.UnixCCompiler recognizes
+ gcc when it has a fully qualified configuration prefix. Initial patch
+ by Arfrever.
+
+- Issue #7105: Make WeakKeyDictionary and WeakValueDictionary robust against
+ the destruction of weakref'ed objects while iterating.
+
+- Issue #7455: Fix possible crash in cPickle on invalid input. Patch by
+ Victor Stinner.
+
- Issue #1628205: Socket file objects returned by socket.socket.makefile() now
properly handles EINTR within the read, readline, write & flush methods.
The socket.sendall() method now properly handles interrupted system calls.
@@ -543,6 +613,10 @@
Build
-----
+- Issue #7632: When Py_USING_MEMORY_DEBUGGER is defined, disable the
+ private memory allocation scheme in dtoa.c and use PyMem_Malloc and
+ PyMem_Free instead. Also disable caching of powers of 5.
+
- Issue #6491: Allow --with-dbmliborder to specify that no dbms will be built.
- Issue #6943: Use pkg-config to find the libffi headers when the
@@ -650,6 +724,13 @@
- Removed importlib's custom test discovery code and switched to
unittest.TestLoader.discover().
+Tools/Demos
+-----------
+
+- iobench (a file I/O benchmark) and ccbench (a concurrency benchmark) were
+ added to the `Tools/` directory. They were previously living in the
+ sandbox.
+
What's New in Python 3.1?
=========================
Modified: python/branches/py3k-cdecimal/Misc/RPM/python-3.2.spec
==============================================================================
--- python/branches/py3k-cdecimal/Misc/RPM/python-3.2.spec (original)
+++ python/branches/py3k-cdecimal/Misc/RPM/python-3.2.spec Thu Jan 21 20:32:23 2010
@@ -25,6 +25,11 @@
%define config_ipv6 yes
%define config_ipv6 no
+# Build shared libraries or .a library?
+#WARNING: Commenting out doesn't work. Last line is what's used.
+%define config_sharedlib no
+%define config_sharedlib yes
+
# Location of the HTML directory.
%define config_htmldir /var/www/html/python
@@ -35,7 +40,7 @@
%define name python
#--start constants--
%define version 3.2a0
-%define libver 3.2
+%define libvers 3.2
#--end constants--
%define release 1pydotorg
%define __prefix /usr
@@ -46,6 +51,8 @@
%define binsuffix %(if [ "%{config_binsuffix}" = none ]; then echo ; else echo "%{config_binsuffix}"; fi)
%define include_tkinter %(if [ \\( "%{config_tkinter}" = auto -a -f /usr/bin/wish \\) -o "%{config_tkinter}" = yes ]; then echo 1; else echo 0; fi)
%define libdirname %(( uname -m | egrep -q '_64$' && [ -d /usr/lib64 ] && echo lib64 ) || echo lib)
+%define sharedlib %(if [ "%{config_sharedlib}" = yes ]; then echo --enable-shared; else echo ; fi)
+%define include_sharedlib %(if [ "%{config_sharedlib}" = yes ]; then echo 1; else echo 0; fi)
# detect if documentation is available
%define include_docs %(if [ -f "%{_sourcedir}/html-%{version}.tar.bz2" ]; then echo 1; else echo 0; fi)
@@ -54,7 +61,7 @@
Name: %{name}%{binsuffix}
Version: %{version}
Release: %{release}
-Copyright: Modified CNRI Open Source License
+License: Modified CNRI Open Source License
Group: Development/Languages
Source: Python-%{version}.tar.bz2
%if %{include_docs}
@@ -223,7 +230,14 @@
# BUILD
########
%build
-./configure --enable-unicode=ucs4 %{ipv6} %{pymalloc} --prefix=%{__prefix}
+echo "Setting for ipv6: %{ipv6}"
+echo "Setting for pymalloc: %{pymalloc}"
+echo "Setting for binsuffix: %{binsuffix}"
+echo "Setting for include_tkinter: %{include_tkinter}"
+echo "Setting for libdirname: %{libdirname}"
+echo "Setting for sharedlib: %{sharedlib}"
+echo "Setting for include_sharedlib: %{include_sharedlib}"
+./configure --enable-unicode=ucs4 %{sharedlib} %{ipv6} %{pymalloc} --prefix=%{__prefix}
make
##########
@@ -254,11 +268,10 @@
# add the binsuffix
if [ ! -z "%{binsuffix}" ]
then
- ( cd $RPM_BUILD_ROOT%{__prefix}/bin; rm -f python[0-9a-zA-Z]*;
- mv -f python python"%{binsuffix}" )
- ( cd $RPM_BUILD_ROOT%{__prefix}/man/man1; mv python.1 python%{binsuffix}.1 )
- ( cd $RPM_BUILD_ROOT%{__prefix}/bin; mv -f pydoc pydoc"%{binsuffix}" )
- ( cd $RPM_BUILD_ROOT%{__prefix}/bin; mv -f idle idle"%{binsuffix}" )
+ rm -f $RPM_BUILD_ROOT%{__prefix}/bin/python[0-9a-zA-Z]*
+ ( cd $RPM_BUILD_ROOT%{__prefix}/bin;
+ for file in *; do mv "$file" "$file"%{binsuffix}; done )
+ ( cd $RPM_BUILD_ROOT%{_mandir}/man1; mv python.1 python%{binsuffix}.1 )
fi
########
@@ -273,17 +286,23 @@
# MAKE FILE LISTS
rm -f mainpkg.files
-find "$RPM_BUILD_ROOT""%{__prefix}"/%{libdirname}/python%{libvers}/lib-dynload -type f |
+find "$RPM_BUILD_ROOT""%{__prefix}"/%{libdirname}/python%{libvers} -type f |
sed "s|^${RPM_BUILD_ROOT}|/|" |
- grep -v -e '_tkinter.so$' >mainpkg.files
-find "$RPM_BUILD_ROOT""%{__prefix}"/bin -type f |
+ grep -v -e '/python%{libvers}/config$' -e '_tkinter.so$' >mainpkg.files
+find "$RPM_BUILD_ROOT""%{__prefix}"/bin -type f -o -type l |
sed "s|^${RPM_BUILD_ROOT}|/|" |
+ grep -v -e '/bin/2to3%{binsuffix}$' |
+ grep -v -e '/bin/pydoc%{binsuffix}$' |
+ grep -v -e '/bin/smtpd.py%{binsuffix}$' |
grep -v -e '/bin/idle%{binsuffix}$' >>mainpkg.files
rm -f tools.files
find "$RPM_BUILD_ROOT""%{__prefix}"/%{libdirname}/python%{libvers}/idlelib \
"$RPM_BUILD_ROOT""%{__prefix}"/%{libdirname}/python%{libvers}/Tools -type f |
sed "s|^${RPM_BUILD_ROOT}|/|" >tools.files
+echo "%{__prefix}"/bin/2to3%{binsuffix} >>tools.files
+echo "%{__prefix}"/bin/pydoc%{binsuffix} >>tools.files
+echo "%{__prefix}"/bin/smtpd.py%{binsuffix} >>tools.files
echo "%{__prefix}"/bin/idle%{binsuffix} >>tools.files
######
@@ -341,28 +360,13 @@
%defattr(-,root,root)
%doc Misc/README Misc/cheatsheet Misc/Porting
%doc LICENSE Misc/ACKS Misc/HISTORY Misc/NEWS
-%{__prefix}/man/man1/python%{binsuffix}.1*
+%{_mandir}/man1/python%{binsuffix}.1*
%attr(755,root,root) %dir %{__prefix}/include/python%{libvers}
%attr(755,root,root) %dir %{__prefix}/%{libdirname}/python%{libvers}/
-%{__prefix}/%{libdirname}/python%{libvers}/*.txt
-%{__prefix}/%{libdirname}/python%{libvers}/*.py*
-%{__prefix}/%{libdirname}/python%{libvers}/pdb.doc
-%{__prefix}/%{libdirname}/python%{libvers}/profile.doc
-%{__prefix}/%{libdirname}/python%{libvers}/curses
-%{__prefix}/%{libdirname}/python%{libvers}/distutils
-%{__prefix}/%{libdirname}/python%{libvers}/encodings
-%{__prefix}/%{libdirname}/python%{libvers}/plat-linux2
-%{__prefix}/%{libdirname}/python%{libvers}/site-packages
-%{__prefix}/%{libdirname}/python%{libvers}/test
-%{__prefix}/%{libdirname}/python%{libvers}/xml
-%{__prefix}/%{libdirname}/python%{libvers}/email
-%{__prefix}/%{libdirname}/python%{libvers}/email/mime
-%{__prefix}/%{libdirname}/python%{libvers}/sqlite3
-%{__prefix}/%{libdirname}/python%{libvers}/compiler
-%{__prefix}/%{libdirname}/python%{libvers}/hotshot
-%{__prefix}/%{libdirname}/python%{libvers}/logging
-%{__prefix}/%{libdirname}/python%{libvers}/lib-old
+%if %{include_sharedlib}
+%{__prefix}/%{libdirname}/libpython*
+%endif
%files devel
%defattr(-,root,root)
Modified: python/branches/py3k-cdecimal/Misc/build.sh
==============================================================================
--- python/branches/py3k-cdecimal/Misc/build.sh (original)
+++ python/branches/py3k-cdecimal/Misc/build.sh Thu Jan 21 20:32:23 2010
@@ -214,7 +214,7 @@
## make and run basic tests
F=make-test.out
start=`current_time`
- $PYTHON $REGRTEST_ARGS -u urlfetch >& build/$F
+ $PYTHON $REGRTEST_ARGS -W -u urlfetch >& build/$F
NUM_FAILURES=`count_failures build/$F`
place_summary_first build/$F
update_status "Testing basics ($NUM_FAILURES failures)" "$F" $start
@@ -222,7 +222,7 @@
F=make-test-opt.out
start=`current_time`
- $PYTHON -O $REGRTEST_ARGS -u urlfetch >& build/$F
+ $PYTHON -O $REGRTEST_ARGS -W -u urlfetch >& build/$F
NUM_FAILURES=`count_failures build/$F`
place_summary_first build/$F
update_status "Testing opt ($NUM_FAILURES failures)" "$F" $start
@@ -245,7 +245,7 @@
start=`current_time`
## skip curses when running from cron since there's no terminal
## skip sound since it's not setup on the PSF box (/dev/dsp)
- $PYTHON $REGRTEST_ARGS -uall -x test_curses test_linuxaudiodev test_ossaudiodev $_ALWAYS_SKIP >& build/$F
+ $PYTHON $REGRTEST_ARGS -W -uall -x test_curses test_linuxaudiodev test_ossaudiodev &_ALWAYS_SKIP >& build/$F
NUM_FAILURES=`count_failures build/$F`
place_summary_first build/$F
update_status "Testing all except curses and sound ($NUM_FAILURES failures)" "$F" $start
Modified: python/branches/py3k-cdecimal/Misc/developers.txt
==============================================================================
--- python/branches/py3k-cdecimal/Misc/developers.txt (original)
+++ python/branches/py3k-cdecimal/Misc/developers.txt Thu Jan 21 20:32:23 2010
@@ -20,6 +20,9 @@
Permissions History
-------------------
+- Stefan Krah was given SVN access on January 5 2010 by GFB, at
+ suggestion of Mark Dickinson, for work on the decimal module.
+
- Doug Hellmann was given SVN access on September 19 2009 by GFB, at
suggestion of Jesse Noller, for documentation work.
Modified: python/branches/py3k-cdecimal/Misc/gdbinit
==============================================================================
--- python/branches/py3k-cdecimal/Misc/gdbinit (original)
+++ python/branches/py3k-cdecimal/Misc/gdbinit Thu Jan 21 20:32:23 2010
@@ -115,12 +115,18 @@
# interpreter, but the test can be extended by an interested party). If
# Py_Main <= $pc <= Py_GetArgcArv is true, $pc is in Py_Main(), so the while
# tests succeeds as long as it's not true. In a similar fashion the if
-# statement tests to see if we are in PyEval_EvalFrame().
+# statement tests to see if we are in PyEval_EvalFrameEx().
+
+# Note: The name of the main interpreter function and the function which
+# follow it has changed over time. This version of pystack works with this
+# version of Python. If you try using it with older or newer versions of
+# the interpreter you may will have to change the functions you compare with
+# $pc.
# print the entire Python call stack
define pystack
while $pc < Py_Main || $pc > Py_GetArgcArgv
- if $pc > PyEval_EvalFrame && $pc < PyEval_EvalCodeEx
+ if $pc > PyEval_EvalFrameEx && $pc < PyEval_EvalCodeEx
pyframe
end
up-silently 1
@@ -131,7 +137,7 @@
# print the entire Python call stack - verbose mode
define pystackv
while $pc < Py_Main || $pc > Py_GetArgcArgv
- if $pc > PyEval_EvalFrame && $pc < PyEval_EvalCodeEx
+ if $pc > PyEval_EvalFrameEx && $pc < PyEval_EvalCodeEx
pyframev
end
up-silently 1
Modified: python/branches/py3k-cdecimal/Modules/_ctypes/libffi/fficonfig.py.in
==============================================================================
--- python/branches/py3k-cdecimal/Modules/_ctypes/libffi/fficonfig.py.in (original)
+++ python/branches/py3k-cdecimal/Modules/_ctypes/libffi/fficonfig.py.in Thu Jan 21 20:32:23 2010
@@ -28,8 +28,6 @@
'PA_HPUX': ['src/pa/hpux32.S', 'src/pa/ffi.c'],
}
-ffi_srcdir = '@srcdir@'
ffi_sources += ffi_platforms['@TARGET@']
-ffi_sources = [os.path.join('@srcdir@', f) for f in ffi_sources]
ffi_cflags = '@CFLAGS@'
Modified: python/branches/py3k-cdecimal/Modules/_hashopenssl.c
==============================================================================
--- python/branches/py3k-cdecimal/Modules/_hashopenssl.c (original)
+++ python/branches/py3k-cdecimal/Modules/_hashopenssl.c Thu Jan 21 20:32:23 2010
@@ -1,7 +1,7 @@
/* Module that wraps all OpenSSL hash algorithms */
/*
- * Copyright (C) 2005-2009 Gregory P. Smith (greg at krypto.org)
+ * Copyright (C) 2005-2010 Gregory P. Smith (greg at krypto.org)
* Licensed to PSF under a Contributor Agreement.
*
* Derived from a skeleton of shamodule.c containing work performed by:
Modified: python/branches/py3k-cdecimal/Modules/_pickle.c
==============================================================================
--- python/branches/py3k-cdecimal/Modules/_pickle.c (original)
+++ python/branches/py3k-cdecimal/Modules/_pickle.c Thu Jan 21 20:32:23 2010
@@ -3729,7 +3729,7 @@
*/
if (self->num_marks > 0 && self->marks[self->num_marks - 1] == len) {
self->num_marks--;
- } else if (len >= 0) {
+ } else if (len > 0) {
len--;
Py_DECREF(self->stack->data[len]);
self->stack->length = len;
Modified: python/branches/py3k-cdecimal/Modules/_sre.c
==============================================================================
--- python/branches/py3k-cdecimal/Modules/_sre.c (original)
+++ python/branches/py3k-cdecimal/Modules/_sre.c Thu Jan 21 20:32:23 2010
@@ -2674,6 +2674,10 @@
self = PyObject_NEW_VAR(PatternObject, &Pattern_Type, n);
if (!self)
return NULL;
+ self->weakreflist = NULL;
+ self->pattern = NULL;
+ self->groupindex = NULL;
+ self->indexgroup = NULL;
self->codesize = n;
@@ -2689,7 +2693,7 @@
}
if (PyErr_Occurred()) {
- PyObject_DEL(self);
+ Py_DECREF(self);
return NULL;
}
@@ -3730,7 +3734,7 @@
scanner_dealloc(ScannerObject* self)
{
state_fini(&self->state);
- Py_DECREF(self->pattern);
+ Py_XDECREF(self->pattern);
PyObject_DEL(self);
}
@@ -3860,10 +3864,11 @@
self = PyObject_NEW(ScannerObject, &Scanner_Type);
if (!self)
return NULL;
+ self->pattern = NULL;
string = state_init(&self->state, pattern, string, start, end);
if (!string) {
- PyObject_DEL(self);
+ Py_DECREF(self);
return NULL;
}
Modified: python/branches/py3k-cdecimal/Modules/_testcapimodule.c
==============================================================================
--- python/branches/py3k-cdecimal/Modules/_testcapimodule.c (original)
+++ python/branches/py3k-cdecimal/Modules/_testcapimodule.c Thu Jan 21 20:32:23 2010
@@ -1287,6 +1287,23 @@
#undef CHECK_1_FORMAT
}
+
+static PyObject *
+test_unicode_compare_with_ascii(PyObject *self) {
+ PyObject *py_s = PyUnicode_FromStringAndSize("str\0", 4);
+ int result;
+ if (py_s == NULL)
+ return NULL;
+ result = PyUnicode_CompareWithASCIIString(py_s, "str");
+ Py_DECREF(py_s);
+ if (!result) {
+ PyErr_SetString(TestError, "Python string ending in NULL "
+ "should not compare equal to c string.");
+ return NULL;
+ }
+ Py_RETURN_NONE;
+};
+
/* This is here to provide a docstring for test_descr. */
static PyObject *
test_with_docstring(PyObject *self)
@@ -1756,6 +1773,7 @@
{"test_with_docstring", (PyCFunction)test_with_docstring, METH_NOARGS,
PyDoc_STR("This is a pretty normal docstring.")},
{"test_string_to_double", (PyCFunction)test_string_to_double, METH_NOARGS},
+ {"test_unicode_compare_with_ascii", (PyCFunction)test_unicode_compare_with_ascii, METH_NOARGS},
{"test_capsule", (PyCFunction)test_capsule, METH_NOARGS},
{"getargs_tuple", getargs_tuple, METH_VARARGS},
{"getargs_keywords", (PyCFunction)getargs_keywords,
Modified: python/branches/py3k-cdecimal/Modules/binascii.c
==============================================================================
--- python/branches/py3k-cdecimal/Modules/binascii.c (original)
+++ python/branches/py3k-cdecimal/Modules/binascii.c Thu Jan 21 20:32:23 2010
@@ -294,7 +294,7 @@
}
/* We're lazy and allocate to much (fixed up later) */
- if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len*2+2)) == NULL ) {
+ if ( (rv=PyBytes_FromStringAndSize(NULL, 2 + (bin_len+2)/3*4)) == NULL ) {
PyBuffer_Release(&pbin);
return NULL;
}
@@ -537,6 +537,7 @@
static PyObject *
binascii_a2b_hqx(PyObject *self, PyObject *args)
{
+ Py_buffer pascii;
unsigned char *ascii_data, *bin_data;
int leftbits = 0;
unsigned char this_ch;
@@ -545,19 +546,25 @@
Py_ssize_t len;
int done = 0;
- if ( !PyArg_ParseTuple(args, "t#:a2b_hqx", &ascii_data, &len) )
+ if ( !PyArg_ParseTuple(args, "s*:a2b_hqx", &pascii) )
return NULL;
+ ascii_data = pascii.buf;
+ len = pascii.len;
assert(len >= 0);
- if (len > PY_SSIZE_T_MAX - 2)
+ if (len > PY_SSIZE_T_MAX - 2) {
+ PyBuffer_Release(&pascii);
return PyErr_NoMemory();
+ }
/* Allocate a string that is too big (fixed later)
Add two to the initial length to prevent interning which
would preclude subsequent resizing. */
- if ( (rv=PyBytes_FromStringAndSize(NULL, len+2)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, len+2)) == NULL ) {
+ PyBuffer_Release(&pascii);
return NULL;
+ }
bin_data = (unsigned char *)PyBytes_AS_STRING(rv);
for( ; len > 0 ; len--, ascii_data++ ) {
@@ -567,6 +574,7 @@
continue;
if ( this_ch == FAIL ) {
PyErr_SetString(Error, "Illegal char");
+ PyBuffer_Release(&pascii);
Py_DECREF(rv);
return NULL;
}
@@ -589,6 +597,7 @@
if ( leftbits && !done ) {
PyErr_SetString(Incomplete,
"String has incomplete number of bytes");
+ PyBuffer_Release(&pascii);
Py_DECREF(rv);
return NULL;
}
@@ -600,10 +609,12 @@
}
if (rv) {
PyObject *rrv = Py_BuildValue("Oi", rv, done);
+ PyBuffer_Release(&pascii);
Py_DECREF(rv);
return rrv;
}
+ PyBuffer_Release(&pascii);
return NULL;
}
Modified: python/branches/py3k-cdecimal/Modules/posixmodule.c
==============================================================================
--- python/branches/py3k-cdecimal/Modules/posixmodule.c (original)
+++ python/branches/py3k-cdecimal/Modules/posixmodule.c Thu Jan 21 20:32:23 2010
@@ -580,7 +580,7 @@
release_bytes(PyObject* o)
{
if (PyByteArray_Check(o))
- o->ob_type->tp_as_buffer->bf_releasebuffer(NULL, 0);
+ o->ob_type->tp_as_buffer->bf_releasebuffer(o, 0);
Py_DECREF(o);
}
Modified: python/branches/py3k-cdecimal/Objects/bytearrayobject.c
==============================================================================
--- python/branches/py3k-cdecimal/Objects/bytearrayobject.c (original)
+++ python/branches/py3k-cdecimal/Objects/bytearrayobject.c Thu Jan 21 20:32:23 2010
@@ -5,23 +5,16 @@
#include "structmember.h"
#include "bytes_methods.h"
-static PyByteArrayObject *nullbytes = NULL;
+char _PyByteArray_empty_string[] = "";
void
PyByteArray_Fini(void)
{
- Py_CLEAR(nullbytes);
}
int
PyByteArray_Init(void)
{
- nullbytes = PyObject_New(PyByteArrayObject, &PyByteArray_Type);
- if (nullbytes == NULL)
- return 0;
- nullbytes->ob_bytes = NULL;
- Py_SIZE(nullbytes) = nullbytes->ob_alloc = 0;
- nullbytes->ob_exports = 0;
return 1;
}
@@ -65,10 +58,7 @@
obj->ob_exports++;
return 0;
}
- if (obj->ob_bytes == NULL)
- ptr = "";
- else
- ptr = obj->ob_bytes;
+ ptr = (void *) PyByteArray_AS_STRING(obj);
ret = PyBuffer_FillInfo(view, (PyObject*)obj, ptr, Py_SIZE(obj), 0, flags);
if (ret >= 0) {
obj->ob_exports++;
@@ -152,7 +142,7 @@
Py_DECREF(new);
return PyErr_NoMemory();
}
- if (bytes != NULL)
+ if (bytes != NULL && size > 0)
memcpy(new->ob_bytes, bytes, size);
new->ob_bytes[size] = '\0'; /* Trailing null byte */
}
@@ -1038,15 +1028,16 @@
#define STRINGLIB_LEN PyByteArray_GET_SIZE
#define STRINGLIB_STR PyByteArray_AS_STRING
#define STRINGLIB_NEW PyByteArray_FromStringAndSize
-#define STRINGLIB_EMPTY nullbytes
+#define STRINGLIB_ISSPACE Py_ISSPACE
+#define STRINGLIB_ISLINEBREAK(x) ((x == '\n') || (x == '\r'))
#define STRINGLIB_CHECK_EXACT PyByteArray_CheckExact
#define STRINGLIB_MUTABLE 1
-#define FROM_BYTEARRAY 1
#include "stringlib/fastsearch.h"
#include "stringlib/count.h"
#include "stringlib/find.h"
#include "stringlib/partition.h"
+#include "stringlib/split.h"
#include "stringlib/ctype.h"
#include "stringlib/transmogrify.h"
@@ -1054,21 +1045,20 @@
/* The following Py_LOCAL_INLINE and Py_LOCAL functions
were copied from the old char* style string object. */
-Py_LOCAL_INLINE(void)
-_adjust_indices(Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t len)
-{
- if (*end > len)
- *end = len;
- else if (*end < 0)
- *end += len;
- if (*end < 0)
- *end = 0;
- if (*start < 0)
- *start += len;
- if (*start < 0)
- *start = 0;
-}
-
+/* helper macro to fixup start/end slice values */
+#define ADJUST_INDICES(start, end, len) \
+ if (end > len) \
+ end = len; \
+ else if (end < 0) { \
+ end += len; \
+ if (end < 0) \
+ end = 0; \
+ } \
+ if (start < 0) { \
+ start += len; \
+ if (start < 0) \
+ start = 0; \
+ }
Py_LOCAL_INLINE(Py_ssize_t)
bytearray_find_internal(PyByteArrayObject *self, PyObject *args, int dir)
@@ -1136,10 +1126,10 @@
if (_getbuffer(sub_obj, &vsub) < 0)
return NULL;
- _adjust_indices(&start, &end, PyByteArray_GET_SIZE(self));
+ ADJUST_INDICES(start, end, PyByteArray_GET_SIZE(self));
count_obj = PyLong_FromSsize_t(
- stringlib_count(str + start, end - start, vsub.buf, vsub.len)
+ stringlib_count(str + start, end - start, vsub.buf, vsub.len, PY_SSIZE_T_MAX)
);
PyBuffer_Release(&vsub);
return count_obj;
@@ -1247,7 +1237,7 @@
if (_getbuffer(substr, &vsubstr) < 0)
return -1;
- _adjust_indices(&start, &end, len);
+ ADJUST_INDICES(start, end, len);
if (direction < 0) {
/* startswith */
@@ -1459,20 +1449,11 @@
}
-#define FORWARD 1
-#define REVERSE -1
-
/* find and count characters and substrings */
#define findchar(target, target_len, c) \
((char *)memchr((const void *)(target), c, target_len))
-/* Don't call if length < 2 */
-#define Py_STRING_MATCH(target, offset, pattern, length) \
- (target[offset] == pattern[0] && \
- target[offset+length-1] == pattern[length-1] && \
- !memcmp(target+offset+1, pattern+1, length-2) )
-
/* Bytes ops must return a string, create a copy */
Py_LOCAL(PyByteArrayObject *)
@@ -1500,93 +1481,6 @@
return count;
}
-Py_LOCAL(Py_ssize_t)
-findstring(const char *target, Py_ssize_t target_len,
- const char *pattern, Py_ssize_t pattern_len,
- Py_ssize_t start,
- Py_ssize_t end,
- int direction)
-{
- if (start < 0) {
- start += target_len;
- if (start < 0)
- start = 0;
- }
- if (end > target_len) {
- end = target_len;
- } else if (end < 0) {
- end += target_len;
- if (end < 0)
- end = 0;
- }
-
- /* zero-length substrings always match at the first attempt */
- if (pattern_len == 0)
- return (direction > 0) ? start : end;
-
- end -= pattern_len;
-
- if (direction < 0) {
- for (; end >= start; end--)
- if (Py_STRING_MATCH(target, end, pattern, pattern_len))
- return end;
- } else {
- for (; start <= end; start++)
- if (Py_STRING_MATCH(target, start, pattern, pattern_len))
- return start;
- }
- return -1;
-}
-
-Py_LOCAL_INLINE(Py_ssize_t)
-countstring(const char *target, Py_ssize_t target_len,
- const char *pattern, Py_ssize_t pattern_len,
- Py_ssize_t start,
- Py_ssize_t end,
- int direction, Py_ssize_t maxcount)
-{
- Py_ssize_t count=0;
-
- if (start < 0) {
- start += target_len;
- if (start < 0)
- start = 0;
- }
- if (end > target_len) {
- end = target_len;
- } else if (end < 0) {
- end += target_len;
- if (end < 0)
- end = 0;
- }
-
- /* zero-length substrings match everywhere */
- if (pattern_len == 0 || maxcount == 0) {
- if (target_len+1 < maxcount)
- return target_len+1;
- return maxcount;
- }
-
- end -= pattern_len;
- if (direction < 0) {
- for (; (end >= start); end--)
- if (Py_STRING_MATCH(target, end, pattern, pattern_len)) {
- count++;
- if (--maxcount <= 0) break;
- end -= pattern_len-1;
- }
- } else {
- for (; (start <= end); start++)
- if (Py_STRING_MATCH(target, start, pattern, pattern_len)) {
- count++;
- if (--maxcount <= 0)
- break;
- start += pattern_len-1;
- }
- }
- return count;
-}
-
/* Algorithms for different cases of string replacement */
@@ -1708,10 +1602,9 @@
self_len = PyByteArray_GET_SIZE(self);
self_s = PyByteArray_AS_STRING(self);
- count = countstring(self_s, self_len,
- from_s, from_len,
- 0, self_len, 1,
- maxcount);
+ count = stringlib_count(self_s, self_len,
+ from_s, from_len,
+ maxcount);
if (count == 0) {
/* no matches */
@@ -1730,9 +1623,9 @@
start = self_s;
end = self_s + self_len;
while (count-- > 0) {
- offset = findstring(start, end-start,
- from_s, from_len,
- 0, end-start, FORWARD);
+ offset = stringlib_find(start, end-start,
+ from_s, from_len,
+ 0);
if (offset == -1)
break;
next = start + offset;
@@ -1808,9 +1701,9 @@
self_s = PyByteArray_AS_STRING(self);
self_len = PyByteArray_GET_SIZE(self);
- offset = findstring(self_s, self_len,
- from_s, from_len,
- 0, self_len, FORWARD);
+ offset = stringlib_find(self_s, self_len,
+ from_s, from_len,
+ 0);
if (offset == -1) {
/* No matches; return the original bytes */
return return_self(self);
@@ -1830,9 +1723,9 @@
end = result_s + self_len;
while ( --maxcount > 0) {
- offset = findstring(start, end-start,
- from_s, from_len,
- 0, end-start, FORWARD);
+ offset = stringlib_find(start, end-start,
+ from_s, from_len,
+ 0);
if (offset==-1)
break;
Py_MEMCPY(start+offset, to_s, from_len);
@@ -1925,9 +1818,10 @@
self_s = PyByteArray_AS_STRING(self);
self_len = PyByteArray_GET_SIZE(self);
- count = countstring(self_s, self_len,
- from_s, from_len,
- 0, self_len, FORWARD, maxcount);
+ count = stringlib_count(self_s, self_len,
+ from_s, from_len,
+ maxcount);
+
if (count == 0) {
/* no matches, return unchanged */
return return_self(self);
@@ -1954,9 +1848,9 @@
start = self_s;
end = self_s + self_len;
while (count-- > 0) {
- offset = findstring(start, end-start,
- from_s, from_len,
- 0, end-start, FORWARD);
+ offset = stringlib_find(start, end-start,
+ from_s, from_len,
+ 0);
if (offset == -1)
break;
next = start+offset;
@@ -2085,123 +1979,6 @@
return res;
}
-
-/* Overallocate the initial list to reduce the number of reallocs for small
- split sizes. Eg, "A A A A A A A A A A".split() (10 elements) has three
- resizes, to sizes 4, 8, then 16. Most observed string splits are for human
- text (roughly 11 words per line) and field delimited data (usually 1-10
- fields). For large strings the split algorithms are bandwidth limited
- so increasing the preallocation likely will not improve things.*/
-
-#define MAX_PREALLOC 12
-
-/* 5 splits gives 6 elements */
-#define PREALLOC_SIZE(maxsplit) \
- (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
-
-#define SPLIT_APPEND(data, left, right) \
- str = PyByteArray_FromStringAndSize((data) + (left), \
- (right) - (left)); \
- if (str == NULL) \
- goto onError; \
- if (PyList_Append(list, str)) { \
- Py_DECREF(str); \
- goto onError; \
- } \
- else \
- Py_DECREF(str);
-
-#define SPLIT_ADD(data, left, right) { \
- str = PyByteArray_FromStringAndSize((data) + (left), \
- (right) - (left)); \
- if (str == NULL) \
- goto onError; \
- if (count < MAX_PREALLOC) { \
- PyList_SET_ITEM(list, count, str); \
- } else { \
- if (PyList_Append(list, str)) { \
- Py_DECREF(str); \
- goto onError; \
- } \
- else \
- Py_DECREF(str); \
- } \
- count++; }
-
-/* Always force the list to the expected size. */
-#define FIX_PREALLOC_SIZE(list) Py_SIZE(list) = count
-
-
-Py_LOCAL_INLINE(PyObject *)
-split_char(const char *s, Py_ssize_t len, char ch, Py_ssize_t maxcount)
-{
- register Py_ssize_t i, j, count = 0;
- PyObject *str;
- PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
-
- if (list == NULL)
- return NULL;
-
- i = j = 0;
- while ((j < len) && (maxcount-- > 0)) {
- for(; j < len; j++) {
- /* I found that using memchr makes no difference */
- if (s[j] == ch) {
- SPLIT_ADD(s, i, j);
- i = j = j + 1;
- break;
- }
- }
- }
- if (i <= len) {
- SPLIT_ADD(s, i, len);
- }
- FIX_PREALLOC_SIZE(list);
- return list;
-
- onError:
- Py_DECREF(list);
- return NULL;
-}
-
-
-Py_LOCAL_INLINE(PyObject *)
-split_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxcount)
-{
- register Py_ssize_t i, j, count = 0;
- PyObject *str;
- PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
-
- if (list == NULL)
- return NULL;
-
- for (i = j = 0; i < len; ) {
- /* find a token */
- while (i < len && Py_ISSPACE(s[i]))
- i++;
- j = i;
- while (i < len && !Py_ISSPACE(s[i]))
- i++;
- if (j < i) {
- if (maxcount-- <= 0)
- break;
- SPLIT_ADD(s, j, i);
- while (i < len && Py_ISSPACE(s[i]))
- i++;
- j = i;
- }
- }
- if (j < len) {
- SPLIT_ADD(s, j, len);
- }
- FIX_PREALLOC_SIZE(list);
- return list;
-
- onError:
- Py_DECREF(list);
- return NULL;
-}
-
PyDoc_STRVAR(split__doc__,
"B.split([sep[, maxsplit]]) -> list of bytearrays\n\
\n\
@@ -2213,10 +1990,10 @@
static PyObject *
bytearray_split(PyByteArrayObject *self, PyObject *args)
{
- Py_ssize_t len = PyByteArray_GET_SIZE(self), n, i, j, pos;
- Py_ssize_t maxsplit = -1, count = 0;
+ Py_ssize_t len = PyByteArray_GET_SIZE(self), n;
+ Py_ssize_t maxsplit = -1;
const char *s = PyByteArray_AS_STRING(self), *sub;
- PyObject *list, *str, *subobj = Py_None;
+ PyObject *list, *subobj = Py_None;
Py_buffer vsub;
if (!PyArg_ParseTuple(args, "|On:split", &subobj, &maxsplit))
@@ -2225,73 +2002,18 @@
maxsplit = PY_SSIZE_T_MAX;
if (subobj == Py_None)
- return split_whitespace(s, len, maxsplit);
+ return stringlib_split_whitespace((PyObject*) self, s, len, maxsplit);
if (_getbuffer(subobj, &vsub) < 0)
return NULL;
sub = vsub.buf;
n = vsub.len;
- if (n == 0) {
- PyErr_SetString(PyExc_ValueError, "empty separator");
- PyBuffer_Release(&vsub);
- return NULL;
- }
- if (n == 1) {
- list = split_char(s, len, sub[0], maxsplit);
- PyBuffer_Release(&vsub);
- return list;
- }
-
- list = PyList_New(PREALLOC_SIZE(maxsplit));
- if (list == NULL) {
- PyBuffer_Release(&vsub);
- return NULL;
- }
-
- i = j = 0;
- while (maxsplit-- > 0) {
- pos = fastsearch(s+i, len-i, sub, n, FAST_SEARCH);
- if (pos < 0)
- break;
- j = i+pos;
- SPLIT_ADD(s, i, j);
- i = j + n;
- }
- SPLIT_ADD(s, i, len);
- FIX_PREALLOC_SIZE(list);
+ list = stringlib_split(
+ (PyObject*) self, s, len, sub, n, maxsplit
+ );
PyBuffer_Release(&vsub);
return list;
-
- onError:
- Py_DECREF(list);
- PyBuffer_Release(&vsub);
- return NULL;
-}
-
-/* stringlib's partition shares nullbytes in some cases.
- undo this, we don't want the nullbytes to be shared. */
-static PyObject *
-make_nullbytes_unique(PyObject *result)
-{
- if (result != NULL) {
- int i;
- assert(PyTuple_Check(result));
- assert(PyTuple_GET_SIZE(result) == 3);
- for (i = 0; i < 3; i++) {
- if (PyTuple_GET_ITEM(result, i) == (PyObject *)nullbytes) {
- PyObject *new = PyByteArray_FromStringAndSize(NULL, 0);
- if (new == NULL) {
- Py_DECREF(result);
- result = NULL;
- break;
- }
- Py_DECREF(nullbytes);
- PyTuple_SET_ITEM(result, i, new);
- }
- }
- }
- return result;
}
PyDoc_STRVAR(partition__doc__,
@@ -2318,7 +2040,7 @@
);
Py_DECREF(bytesep);
- return make_nullbytes_unique(result);
+ return result;
}
PyDoc_STRVAR(rpartition__doc__,
@@ -2346,81 +2068,7 @@
);
Py_DECREF(bytesep);
- return make_nullbytes_unique(result);
-}
-
-Py_LOCAL_INLINE(PyObject *)
-rsplit_char(const char *s, Py_ssize_t len, char ch, Py_ssize_t maxcount)
-{
- register Py_ssize_t i, j, count=0;
- PyObject *str;
- PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
-
- if (list == NULL)
- return NULL;
-
- i = j = len - 1;
- while ((i >= 0) && (maxcount-- > 0)) {
- for (; i >= 0; i--) {
- if (s[i] == ch) {
- SPLIT_ADD(s, i + 1, j + 1);
- j = i = i - 1;
- break;
- }
- }
- }
- if (j >= -1) {
- SPLIT_ADD(s, 0, j + 1);
- }
- FIX_PREALLOC_SIZE(list);
- if (PyList_Reverse(list) < 0)
- goto onError;
-
- return list;
-
- onError:
- Py_DECREF(list);
- return NULL;
-}
-
-Py_LOCAL_INLINE(PyObject *)
-rsplit_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxcount)
-{
- register Py_ssize_t i, j, count = 0;
- PyObject *str;
- PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
-
- if (list == NULL)
- return NULL;
-
- for (i = j = len - 1; i >= 0; ) {
- /* find a token */
- while (i >= 0 && Py_ISSPACE(s[i]))
- i--;
- j = i;
- while (i >= 0 && !Py_ISSPACE(s[i]))
- i--;
- if (j > i) {
- if (maxcount-- <= 0)
- break;
- SPLIT_ADD(s, i + 1, j + 1);
- while (i >= 0 && Py_ISSPACE(s[i]))
- i--;
- j = i;
- }
- }
- if (j >= 0) {
- SPLIT_ADD(s, 0, j + 1);
- }
- FIX_PREALLOC_SIZE(list);
- if (PyList_Reverse(list) < 0)
- goto onError;
-
- return list;
-
- onError:
- Py_DECREF(list);
- return NULL;
+ return result;
}
PyDoc_STRVAR(rsplit__doc__,
@@ -2435,10 +2083,10 @@
static PyObject *
bytearray_rsplit(PyByteArrayObject *self, PyObject *args)
{
- Py_ssize_t len = PyByteArray_GET_SIZE(self), n, j, pos;
- Py_ssize_t maxsplit = -1, count = 0;
+ Py_ssize_t len = PyByteArray_GET_SIZE(self), n;
+ Py_ssize_t maxsplit = -1;
const char *s = PyByteArray_AS_STRING(self), *sub;
- PyObject *list, *str, *subobj = Py_None;
+ PyObject *list, *subobj = Py_None;
Py_buffer vsub;
if (!PyArg_ParseTuple(args, "|On:rsplit", &subobj, &maxsplit))
@@ -2447,50 +2095,18 @@
maxsplit = PY_SSIZE_T_MAX;
if (subobj == Py_None)
- return rsplit_whitespace(s, len, maxsplit);
+ return stringlib_rsplit_whitespace((PyObject*) self, s, len, maxsplit);
if (_getbuffer(subobj, &vsub) < 0)
return NULL;
sub = vsub.buf;
n = vsub.len;
- if (n == 0) {
- PyErr_SetString(PyExc_ValueError, "empty separator");
- PyBuffer_Release(&vsub);
- return NULL;
- }
- else if (n == 1) {
- list = rsplit_char(s, len, sub[0], maxsplit);
- PyBuffer_Release(&vsub);
- return list;
- }
-
- list = PyList_New(PREALLOC_SIZE(maxsplit));
- if (list == NULL) {
- PyBuffer_Release(&vsub);
- return NULL;
- }
-
- j = len;
-
- while (maxsplit-- > 0) {
- pos = fastsearch(s, j, sub, n, FAST_RSEARCH);
- if (pos < 0)
- break;
- SPLIT_ADD(s, pos + n, j);
- j = pos;
- }
- SPLIT_ADD(s, 0, j);
- FIX_PREALLOC_SIZE(list);
- if (PyList_Reverse(list) < 0)
- goto onError;
+ list = stringlib_rsplit(
+ (PyObject*) self, s, len, sub, n, maxsplit
+ );
PyBuffer_Release(&vsub);
return list;
-
-onError:
- Py_DECREF(list);
- PyBuffer_Release(&vsub);
- return NULL;
}
PyDoc_STRVAR(reverse__doc__,
@@ -2956,6 +2572,27 @@
return NULL;
}
+PyDoc_STRVAR(splitlines__doc__,
+"B.splitlines([keepends]) -> list of lines\n\
+\n\
+Return a list of the lines in B, breaking at line boundaries.\n\
+Line breaks are not included in the resulting list unless keepends\n\
+is given and true.");
+
+static PyObject*
+bytearray_splitlines(PyObject *self, PyObject *args)
+{
+ int keepends = 0;
+
+ if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends))
+ return NULL;
+
+ return stringlib_splitlines(
+ (PyObject*) self, PyByteArray_AS_STRING(self),
+ PyByteArray_GET_SIZE(self), keepends
+ );
+}
+
PyDoc_STRVAR(fromhex_doc,
"bytearray.fromhex(string) -> bytearray (static method)\n\
\n\
@@ -3134,7 +2771,7 @@
{"rsplit", (PyCFunction)bytearray_rsplit, METH_VARARGS, rsplit__doc__},
{"rstrip", (PyCFunction)bytearray_rstrip, METH_VARARGS, rstrip__doc__},
{"split", (PyCFunction)bytearray_split, METH_VARARGS, split__doc__},
- {"splitlines", (PyCFunction)stringlib_splitlines, METH_VARARGS,
+ {"splitlines", (PyCFunction)bytearray_splitlines, METH_VARARGS,
splitlines__doc__},
{"startswith", (PyCFunction)bytearray_startswith, METH_VARARGS ,
startswith__doc__},
Modified: python/branches/py3k-cdecimal/Objects/bytesobject.c
==============================================================================
--- python/branches/py3k-cdecimal/Objects/bytesobject.c (original)
+++ python/branches/py3k-cdecimal/Objects/bytesobject.c Thu Jan 21 20:32:23 2010
@@ -56,7 +56,7 @@
If `str' is NULL then PyBytes_FromStringAndSize() will allocate `size+1'
bytes (setting the last byte to the null terminating character) and you can
fill in the data yourself. If `str' is non-NULL then the resulting
- PyString object must be treated as immutable and you must not fill in nor
+ PyBytes object must be treated as immutable and you must not fill in nor
alter the data yourself, since the strings may be shared.
The PyObject member `op->ob_size', which denotes the number of "extra
@@ -568,9 +568,9 @@
#include "stringlib/count.h"
#include "stringlib/find.h"
#include "stringlib/partition.h"
+#include "stringlib/split.h"
#include "stringlib/ctype.h"
-#define STRINGLIB_MUTABLE 0
#include "stringlib/transmogrify.h"
PyObject *
@@ -1000,133 +1000,6 @@
#define STRIPNAME(i) (stripformat[i]+3)
-
-/* Don't call if length < 2 */
-#define Py_STRING_MATCH(target, offset, pattern, length) \
- (target[offset] == pattern[0] && \
- target[offset+length-1] == pattern[length-1] && \
- !memcmp(target+offset+1, pattern+1, length-2) )
-
-
-/* Overallocate the initial list to reduce the number of reallocs for small
- split sizes. Eg, "A A A A A A A A A A".split() (10 elements) has three
- resizes, to sizes 4, 8, then 16. Most observed string splits are for human
- text (roughly 11 words per line) and field delimited data (usually 1-10
- fields). For large strings the split algorithms are bandwidth limited
- so increasing the preallocation likely will not improve things.*/
-
-#define MAX_PREALLOC 12
-
-/* 5 splits gives 6 elements */
-#define PREALLOC_SIZE(maxsplit) \
- (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
-
-#define SPLIT_ADD(data, left, right) { \
- str = PyBytes_FromStringAndSize((data) + (left), \
- (right) - (left)); \
- if (str == NULL) \
- goto onError; \
- if (count < MAX_PREALLOC) { \
- PyList_SET_ITEM(list, count, str); \
- } else { \
- if (PyList_Append(list, str)) { \
- Py_DECREF(str); \
- goto onError; \
- } \
- else \
- Py_DECREF(str); \
- } \
- count++; }
-
-/* Always force the list to the expected size. */
-#define FIX_PREALLOC_SIZE(list) Py_SIZE(list) = count
-
-#define SKIP_SPACE(s, i, len) { while (i<len && ISSPACE(s[i])) i++; }
-#define SKIP_NONSPACE(s, i, len) { while (i<len && !ISSPACE(s[i])) i++; }
-#define RSKIP_SPACE(s, i) { while (i>=0 && ISSPACE(s[i])) i--; }
-#define RSKIP_NONSPACE(s, i) { while (i>=0 && !ISSPACE(s[i])) i--; }
-
-Py_LOCAL_INLINE(PyObject *)
-split_whitespace(PyBytesObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
-{
- const char *s = PyBytes_AS_STRING(self);
- Py_ssize_t i, j, count=0;
- PyObject *str;
- PyObject *list = PyList_New(PREALLOC_SIZE(maxsplit));
-
- if (list == NULL)
- return NULL;
-
- i = j = 0;
-
- while (maxsplit-- > 0) {
- SKIP_SPACE(s, i, len);
- if (i==len) break;
- j = i; i++;
- SKIP_NONSPACE(s, i, len);
- if (j == 0 && i == len && PyBytes_CheckExact(self)) {
- /* No whitespace in self, so just use it as list[0] */
- Py_INCREF(self);
- PyList_SET_ITEM(list, 0, (PyObject *)self);
- count++;
- break;
- }
- SPLIT_ADD(s, j, i);
- }
-
- if (i < len) {
- /* Only occurs when maxsplit was reached */
- /* Skip any remaining whitespace and copy to end of string */
- SKIP_SPACE(s, i, len);
- if (i != len)
- SPLIT_ADD(s, i, len);
- }
- FIX_PREALLOC_SIZE(list);
- return list;
- onError:
- Py_DECREF(list);
- return NULL;
-}
-
-Py_LOCAL_INLINE(PyObject *)
-split_char(PyBytesObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
-{
- const char *s = PyBytes_AS_STRING(self);
- register Py_ssize_t i, j, count=0;
- PyObject *str;
- PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
-
- if (list == NULL)
- return NULL;
-
- i = j = 0;
- while ((j < len) && (maxcount-- > 0)) {
- for(; j<len; j++) {
- /* I found that using memchr makes no difference */
- if (s[j] == ch) {
- SPLIT_ADD(s, i, j);
- i = j = j + 1;
- break;
- }
- }
- }
- if (i == 0 && count == 0 && PyBytes_CheckExact(self)) {
- /* ch not in self, so just use self as list[0] */
- Py_INCREF(self);
- PyList_SET_ITEM(list, 0, (PyObject *)self);
- count++;
- }
- else if (i <= len) {
- SPLIT_ADD(s, i, len);
- }
- FIX_PREALLOC_SIZE(list);
- return list;
-
- onError:
- Py_DECREF(list);
- return NULL;
-}
-
PyDoc_STRVAR(split__doc__,
"B.split([sep[, maxsplit]]) -> list of bytes\n\
\n\
@@ -1138,74 +1011,26 @@
static PyObject *
bytes_split(PyBytesObject *self, PyObject *args)
{
- Py_ssize_t len = PyBytes_GET_SIZE(self), n, i, j;
- Py_ssize_t maxsplit = -1, count=0;
+ Py_ssize_t len = PyBytes_GET_SIZE(self), n;
+ Py_ssize_t maxsplit = -1;
const char *s = PyBytes_AS_STRING(self), *sub;
Py_buffer vsub;
- PyObject *list, *str, *subobj = Py_None;
-#ifdef USE_FAST
- Py_ssize_t pos;
-#endif
+ PyObject *list, *subobj = Py_None;
if (!PyArg_ParseTuple(args, "|On:split", &subobj, &maxsplit))
return NULL;
if (maxsplit < 0)
maxsplit = PY_SSIZE_T_MAX;
if (subobj == Py_None)
- return split_whitespace(self, len, maxsplit);
+ return stringlib_split_whitespace((PyObject*) self, s, len, maxsplit);
if (_getbuffer(subobj, &vsub) < 0)
return NULL;
sub = vsub.buf;
n = vsub.len;
- if (n == 0) {
- PyErr_SetString(PyExc_ValueError, "empty separator");
- PyBuffer_Release(&vsub);
- return NULL;
- }
- else if (n == 1) {
- list = split_char(self, len, sub[0], maxsplit);
- PyBuffer_Release(&vsub);
- return list;
- }
-
- list = PyList_New(PREALLOC_SIZE(maxsplit));
- if (list == NULL) {
- PyBuffer_Release(&vsub);
- return NULL;
- }
-
-#ifdef USE_FAST
- i = j = 0;
- while (maxsplit-- > 0) {
- pos = fastsearch(s+i, len-i, sub, n, FAST_SEARCH);
- if (pos < 0)
- break;
- j = i+pos;
- SPLIT_ADD(s, i, j);
- i = j + n;
- }
-#else
- i = j = 0;
- while ((j+n <= len) && (maxsplit-- > 0)) {
- for (; j+n <= len; j++) {
- if (Py_STRING_MATCH(s, j, sub, n)) {
- SPLIT_ADD(s, i, j);
- i = j = j + n;
- break;
- }
- }
- }
-#endif
- SPLIT_ADD(s, i, len);
- FIX_PREALLOC_SIZE(list);
+ list = stringlib_split((PyObject*) self, s, len, sub, n, maxsplit);
PyBuffer_Release(&vsub);
return list;
-
- onError:
- Py_DECREF(list);
- PyBuffer_Release(&vsub);
- return NULL;
}
PyDoc_STRVAR(partition__doc__,
@@ -1263,90 +1088,6 @@
);
}
-Py_LOCAL_INLINE(PyObject *)
-rsplit_whitespace(PyBytesObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
-{
- const char *s = PyBytes_AS_STRING(self);
- Py_ssize_t i, j, count=0;
- PyObject *str;
- PyObject *list = PyList_New(PREALLOC_SIZE(maxsplit));
-
- if (list == NULL)
- return NULL;
-
- i = j = len-1;
-
- while (maxsplit-- > 0) {
- RSKIP_SPACE(s, i);
- if (i<0) break;
- j = i; i--;
- RSKIP_NONSPACE(s, i);
- if (j == len-1 && i < 0 && PyBytes_CheckExact(self)) {
- /* No whitespace in self, so just use it as list[0] */
- Py_INCREF(self);
- PyList_SET_ITEM(list, 0, (PyObject *)self);
- count++;
- break;
- }
- SPLIT_ADD(s, i + 1, j + 1);
- }
- if (i >= 0) {
- /* Only occurs when maxsplit was reached. Skip any remaining
- whitespace and copy to beginning of string. */
- RSKIP_SPACE(s, i);
- if (i >= 0)
- SPLIT_ADD(s, 0, i + 1);
-
- }
- FIX_PREALLOC_SIZE(list);
- if (PyList_Reverse(list) < 0)
- goto onError;
- return list;
- onError:
- Py_DECREF(list);
- return NULL;
-}
-
-Py_LOCAL_INLINE(PyObject *)
-rsplit_char(PyBytesObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
-{
- const char *s = PyBytes_AS_STRING(self);
- register Py_ssize_t i, j, count=0;
- PyObject *str;
- PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
-
- if (list == NULL)
- return NULL;
-
- i = j = len - 1;
- while ((i >= 0) && (maxcount-- > 0)) {
- for (; i >= 0; i--) {
- if (s[i] == ch) {
- SPLIT_ADD(s, i + 1, j + 1);
- j = i = i - 1;
- break;
- }
- }
- }
- if (i < 0 && count == 0 && PyBytes_CheckExact(self)) {
- /* ch not in self, so just use self as list[0] */
- Py_INCREF(self);
- PyList_SET_ITEM(list, 0, (PyObject *)self);
- count++;
- }
- else if (j >= -1) {
- SPLIT_ADD(s, 0, j + 1);
- }
- FIX_PREALLOC_SIZE(list);
- if (PyList_Reverse(list) < 0)
- goto onError;
- return list;
-
- onError:
- Py_DECREF(list);
- return NULL;
-}
-
PyDoc_STRVAR(rsplit__doc__,
"B.rsplit([sep[, maxsplit]]) -> list of bytes\n\
\n\
@@ -1360,71 +1101,28 @@
static PyObject *
bytes_rsplit(PyBytesObject *self, PyObject *args)
{
- Py_ssize_t len = PyBytes_GET_SIZE(self), n, i, j;
- Py_ssize_t maxsplit = -1, count=0;
- const char *s, *sub;
+ Py_ssize_t len = PyBytes_GET_SIZE(self), n;
+ Py_ssize_t maxsplit = -1;
+ const char *s = PyBytes_AS_STRING(self), *sub;
Py_buffer vsub;
- PyObject *list, *str, *subobj = Py_None;
+ PyObject *list, *subobj = Py_None;
if (!PyArg_ParseTuple(args, "|On:rsplit", &subobj, &maxsplit))
return NULL;
if (maxsplit < 0)
maxsplit = PY_SSIZE_T_MAX;
if (subobj == Py_None)
- return rsplit_whitespace(self, len, maxsplit);
+ return stringlib_rsplit_whitespace((PyObject*) self, s, len, maxsplit);
if (_getbuffer(subobj, &vsub) < 0)
return NULL;
sub = vsub.buf;
n = vsub.len;
- if (n == 0) {
- PyErr_SetString(PyExc_ValueError, "empty separator");
- PyBuffer_Release(&vsub);
- return NULL;
- }
- else if (n == 1) {
- list = rsplit_char(self, len, sub[0], maxsplit);
- PyBuffer_Release(&vsub);
- return list;
- }
-
- list = PyList_New(PREALLOC_SIZE(maxsplit));
- if (list == NULL) {
- PyBuffer_Release(&vsub);
- return NULL;
- }
-
- j = len;
- i = j - n;
-
- s = PyBytes_AS_STRING(self);
- while ( (i >= 0) && (maxsplit-- > 0) ) {
- for (; i>=0; i--) {
- if (Py_STRING_MATCH(s, i, sub, n)) {
- SPLIT_ADD(s, i + n, j);
- j = i;
- i -= n;
- break;
- }
- }
- }
- SPLIT_ADD(s, 0, j);
- FIX_PREALLOC_SIZE(list);
- if (PyList_Reverse(list) < 0)
- goto onError;
+ list = stringlib_rsplit((PyObject*) self, s, len, sub, n, maxsplit);
PyBuffer_Release(&vsub);
return list;
-
-onError:
- Py_DECREF(list);
- PyBuffer_Release(&vsub);
- return NULL;
}
-#undef SPLIT_ADD
-#undef MAX_PREALLOC
-#undef PREALLOC_SIZE
-
PyDoc_STRVAR(join__doc__,
"B.join(iterable_of_bytes) -> bytes\n\
@@ -1531,20 +1229,20 @@
return bytes_join(sep, x);
}
-Py_LOCAL_INLINE(void)
-bytes_adjust_indices(Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t len)
-{
- if (*end > len)
- *end = len;
- else if (*end < 0)
- *end += len;
- if (*end < 0)
- *end = 0;
- if (*start < 0)
- *start += len;
- if (*start < 0)
- *start = 0;
-}
+/* helper macro to fixup start/end slice values */
+#define ADJUST_INDICES(start, end, len) \
+ if (end > len) \
+ end = len; \
+ else if (end < 0) { \
+ end += len; \
+ if (end < 0) \
+ end = 0; \
+ } \
+ if (start < 0) { \
+ start += len; \
+ if (start < 0) \
+ start = 0; \
+ }
Py_LOCAL_INLINE(Py_ssize_t)
bytes_find_internal(PyBytesObject *self, PyObject *args, int dir)
@@ -1591,7 +1289,7 @@
PyDoc_STRVAR(find__doc__,
"B.find(sub[, start[, end]]) -> int\n\
\n\
-Return the lowest index in S where substring sub is found,\n\
+Return the lowest index in B where substring sub is found,\n\
such that sub is contained within s[start:end]. Optional\n\
arguments start and end are interpreted as in slice notation.\n\
\n\
@@ -1801,7 +1499,7 @@
"B.count(sub[, start[, end]]) -> int\n\
\n\
Return the number of non-overlapping occurrences of substring sub in\n\
-string S[start:end]. Optional arguments start and end are interpreted\n\
+string B[start:end]. Optional arguments start and end are interpreted\n\
as in slice notation.");
static PyObject *
@@ -1823,10 +1521,10 @@
else if (PyObject_AsCharBuffer(sub_obj, &sub, &sub_len))
return NULL;
- bytes_adjust_indices(&start, &end, PyBytes_GET_SIZE(self));
+ ADJUST_INDICES(start, end, PyBytes_GET_SIZE(self));
return PyLong_FromSsize_t(
- stringlib_count(str + start, end - start, sub, sub_len)
+ stringlib_count(str + start, end - start, sub, sub_len, PY_SSIZE_T_MAX)
);
}
@@ -1943,9 +1641,6 @@
return _Py_bytes_maketrans(args);
}
-#define FORWARD 1
-#define REVERSE -1
-
/* find and count characters and substrings */
#define findchar(target, target_len, c) \
@@ -1981,94 +1676,6 @@
return count;
}
-Py_LOCAL(Py_ssize_t)
-findstring(const char *target, Py_ssize_t target_len,
- const char *pattern, Py_ssize_t pattern_len,
- Py_ssize_t start,
- Py_ssize_t end,
- int direction)
-{
- if (start < 0) {
- start += target_len;
- if (start < 0)
- start = 0;
- }
- if (end > target_len) {
- end = target_len;
- } else if (end < 0) {
- end += target_len;
- if (end < 0)
- end = 0;
- }
-
- /* zero-length substrings always match at the first attempt */
- if (pattern_len == 0)
- return (direction > 0) ? start : end;
-
- end -= pattern_len;
-
- if (direction < 0) {
- for (; end >= start; end--)
- if (Py_STRING_MATCH(target, end, pattern, pattern_len))
- return end;
- } else {
- for (; start <= end; start++)
- if (Py_STRING_MATCH(target, start,pattern,pattern_len))
- return start;
- }
- return -1;
-}
-
-Py_LOCAL_INLINE(Py_ssize_t)
-countstring(const char *target, Py_ssize_t target_len,
- const char *pattern, Py_ssize_t pattern_len,
- Py_ssize_t start,
- Py_ssize_t end,
- int direction, Py_ssize_t maxcount)
-{
- Py_ssize_t count=0;
-
- if (start < 0) {
- start += target_len;
- if (start < 0)
- start = 0;
- }
- if (end > target_len) {
- end = target_len;
- } else if (end < 0) {
- end += target_len;
- if (end < 0)
- end = 0;
- }
-
- /* zero-length substrings match everywhere */
- if (pattern_len == 0 || maxcount == 0) {
- if (target_len+1 < maxcount)
- return target_len+1;
- return maxcount;
- }
-
- end -= pattern_len;
- if (direction < 0) {
- for (; (end >= start); end--)
- if (Py_STRING_MATCH(target, end,pattern,pattern_len)) {
- count++;
- if (--maxcount <= 0) break;
- end -= pattern_len-1;
- }
- } else {
- for (; (start <= end); start++)
- if (Py_STRING_MATCH(target, start,
- pattern, pattern_len)) {
- count++;
- if (--maxcount <= 0)
- break;
- start += pattern_len-1;
- }
- }
- return count;
-}
-
/* Algorithms for different cases of string replacement */
@@ -2189,10 +1796,9 @@
self_len = PyBytes_GET_SIZE(self);
self_s = PyBytes_AS_STRING(self);
- count = countstring(self_s, self_len,
- from_s, from_len,
- 0, self_len, 1,
- maxcount);
+ count = stringlib_count(self_s, self_len,
+ from_s, from_len,
+ maxcount);
if (count == 0) {
/* no matches */
@@ -2211,9 +1817,9 @@
start = self_s;
end = self_s + self_len;
while (count-- > 0) {
- offset = findstring(start, end-start,
- from_s, from_len,
- 0, end-start, FORWARD);
+ offset = stringlib_find(start, end-start,
+ from_s, from_len,
+ 0);
if (offset == -1)
break;
next = start + offset;
@@ -2289,9 +1895,9 @@
self_s = PyBytes_AS_STRING(self);
self_len = PyBytes_GET_SIZE(self);
- offset = findstring(self_s, self_len,
- from_s, from_len,
- 0, self_len, FORWARD);
+ offset = stringlib_find(self_s, self_len,
+ from_s, from_len,
+ 0);
if (offset == -1) {
/* No matches; return the original string */
return return_self(self);
@@ -2311,9 +1917,9 @@
end = result_s + self_len;
while ( --maxcount > 0) {
- offset = findstring(start, end-start,
- from_s, from_len,
- 0, end-start, FORWARD);
+ offset = stringlib_find(start, end-start,
+ from_s, from_len,
+ 0);
if (offset==-1)
break;
Py_MEMCPY(start+offset, to_s, from_len);
@@ -2407,9 +2013,10 @@
self_s = PyBytes_AS_STRING(self);
self_len = PyBytes_GET_SIZE(self);
- count = countstring(self_s, self_len,
- from_s, from_len,
- 0, self_len, FORWARD, maxcount);
+ count = stringlib_count(self_s, self_len,
+ from_s, from_len,
+ maxcount);
+
if (count == 0) {
/* no matches, return unchanged */
return return_self(self);
@@ -2438,9 +2045,9 @@
start = self_s;
end = self_s + self_len;
while (count-- > 0) {
- offset = findstring(start, end-start,
- from_s, from_len,
- 0, end-start, FORWARD);
+ offset = stringlib_find(start, end-start,
+ from_s, from_len,
+ 0);
if (offset == -1)
break;
next = start+offset;
@@ -2598,7 +2205,7 @@
return -1;
str = PyBytes_AS_STRING(self);
- bytes_adjust_indices(&start, &end, len);
+ ADJUST_INDICES(start, end, len);
if (direction < 0) {
/* startswith */
@@ -2703,7 +2310,7 @@
PyDoc_STRVAR(decode__doc__,
"B.decode([encoding[, errors]]) -> str\n\
\n\
-Decode S using the codec registered for encoding. encoding defaults\n\
+Decode B using the codec registered for encoding. encoding defaults\n\
to the default encoding. errors may be given to set a different error\n\
handling scheme. Default is 'strict' meaning that encoding errors raise\n\
a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'\n\
@@ -2725,6 +2332,28 @@
}
+PyDoc_STRVAR(splitlines__doc__,
+"B.splitlines([keepends]) -> list of lines\n\
+\n\
+Return a list of the lines in B, breaking at line boundaries.\n\
+Line breaks are not included in the resulting list unless keepends\n\
+is given and true.");
+
+static PyObject*
+bytes_splitlines(PyObject *self, PyObject *args)
+{
+ int keepends = 0;
+
+ if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends))
+ return NULL;
+
+ return stringlib_splitlines(
+ (PyObject*) self, PyBytes_AS_STRING(self),
+ PyBytes_GET_SIZE(self), keepends
+ );
+}
+
+
PyDoc_STRVAR(fromhex_doc,
"bytes.fromhex(string) -> bytes\n\
\n\
@@ -2807,7 +2436,7 @@
static PyObject *
bytes_getnewargs(PyBytesObject *v)
{
- return Py_BuildValue("(s#)", v->ob_sval, Py_SIZE(v));
+ return Py_BuildValue("(y#)", v->ob_sval, Py_SIZE(v));
}
@@ -2857,7 +2486,7 @@
{"rsplit", (PyCFunction)bytes_rsplit, METH_VARARGS, rsplit__doc__},
{"rstrip", (PyCFunction)bytes_rstrip, METH_VARARGS, rstrip__doc__},
{"split", (PyCFunction)bytes_split, METH_VARARGS, split__doc__},
- {"splitlines", (PyCFunction)stringlib_splitlines, METH_VARARGS,
+ {"splitlines", (PyCFunction)bytes_splitlines, METH_VARARGS,
splitlines__doc__},
{"startswith", (PyCFunction)bytes_startswith, METH_VARARGS,
startswith__doc__},
@@ -2979,17 +2608,62 @@
return NULL;
}
+ if (PyList_CheckExact(x)) {
+ new = PyBytes_FromStringAndSize(NULL, Py_SIZE(x));
+ if (new == NULL)
+ return NULL;
+ for (i = 0; i < Py_SIZE(x); i++) {
+ Py_ssize_t value = PyNumber_AsSsize_t(
+ PyList_GET_ITEM(x, i), PyExc_ValueError);
+ if (value == -1 && PyErr_Occurred()) {
+ Py_DECREF(new);
+ return NULL;
+ }
+ if (value < 0 || value >= 256) {
+ PyErr_SetString(PyExc_ValueError,
+ "bytes must be in range(0, 256)");
+ Py_DECREF(new);
+ return NULL;
+ }
+ ((PyBytesObject *)new)->ob_sval[i] = value;
+ }
+ return new;
+ }
+ if (PyTuple_CheckExact(x)) {
+ new = PyBytes_FromStringAndSize(NULL, Py_SIZE(x));
+ if (new == NULL)
+ return NULL;
+ for (i = 0; i < Py_SIZE(x); i++) {
+ Py_ssize_t value = PyNumber_AsSsize_t(
+ PyTuple_GET_ITEM(x, i), PyExc_ValueError);
+ if (value == -1 && PyErr_Occurred()) {
+ Py_DECREF(new);
+ return NULL;
+ }
+ if (value < 0 || value >= 256) {
+ PyErr_SetString(PyExc_ValueError,
+ "bytes must be in range(0, 256)");
+ Py_DECREF(new);
+ return NULL;
+ }
+ ((PyBytesObject *)new)->ob_sval[i] = value;
+ }
+ return new;
+ }
+
/* For iterator version, create a string object and resize as needed */
- /* XXX(gb): is 64 a good value? also, optimize if length is known */
- /* XXX(guido): perhaps use Pysequence_Fast() -- I can't imagine the
- input being a truly long iterator. */
- size = 64;
+ size = _PyObject_LengthHint(x, 64);
+ if (size == -1 && PyErr_Occurred())
+ return NULL;
+ /* Allocate an extra byte to prevent PyBytes_FromStringAndSize() from
+ returning a shared empty bytes string. This required because we
+ want to call _PyBytes_Resize() the returned object, which we can
+ only do on bytes objects with refcount == 1. */
+ size += 1;
new = PyBytes_FromStringAndSize(NULL, size);
if (new == NULL)
return NULL;
- /* XXX Optimize this if the arguments is a list, tuple */
-
/* Get the iterator */
it = PyObject_GetIter(x);
if (it == NULL)
@@ -3023,7 +2697,7 @@
/* Append the byte */
if (i >= size) {
- size *= 2;
+ size = 2 * size + 1;
if (_PyBytes_Resize(&new, size) < 0)
goto error;
}
@@ -3194,7 +2868,7 @@
/* _PyBytes_FormatLong emulates the format codes d, u, o, x and X, and
* the F_ALT flag, for Python's long (unbounded) ints. It's not used for
* Python's regular ints.
- * Return value: a new PyString*, or NULL if error.
+ * Return value: a new PyBytes*, or NULL if error.
* . *pbuf is set to point into it,
* *plen set to the # of chars following that.
* Caller must decref it when done using pbuf.
Modified: python/branches/py3k-cdecimal/Objects/longobject.c
==============================================================================
--- python/branches/py3k-cdecimal/Objects/longobject.c (original)
+++ python/branches/py3k-cdecimal/Objects/longobject.c Thu Jan 21 20:32:23 2010
@@ -4296,6 +4296,187 @@
}
#endif
+
+PyDoc_STRVAR(long_to_bytes_doc,
+"int.to_bytes(length, byteorder, *, signed=False) -> bytes\n\
+\n\
+Return an array of bytes representing an integer.\n\
+\n\
+The integer is represented using length bytes. An OverflowError is\n\
+raised if the integer is not representable with the given number of\n\
+bytes.\n\
+\n\
+The byteorder argument determines the byte order used to represent the\n\
+integer. If byteorder is 'big', the most significant byte is at the\n\
+beginning of the byte array. If byteorder is 'little', the most\n\
+significant byte is at the end of the byte array. To request the native\n\
+byte order of the host system, use `sys.byteorder' as the byte order value.\n\
+\n\
+The signed keyword-only argument determines whether two's complement is\n\
+used to represent the integer. If signed is False and a negative integer\n\
+is given, an OverflowError is raised.");
+
+static PyObject *
+long_to_bytes(PyLongObject *v, PyObject *args, PyObject *kwds)
+{
+ PyObject *byteorder_str;
+ PyObject *is_signed_obj = NULL;
+ Py_ssize_t length;
+ int little_endian;
+ int is_signed;
+ PyObject *bytes;
+ static char *kwlist[] = {"length", "byteorder", "signed", NULL};
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "nU|O:to_bytes", kwlist,
+ &length, &byteorder_str,
+ &is_signed_obj))
+ return NULL;
+
+ if (args != NULL && Py_SIZE(args) > 2) {
+ PyErr_SetString(PyExc_TypeError,
+ "'signed' is a keyword-only argument");
+ return NULL;
+ }
+
+ if (!PyUnicode_CompareWithASCIIString(byteorder_str, "little"))
+ little_endian = 1;
+ else if (!PyUnicode_CompareWithASCIIString(byteorder_str, "big"))
+ little_endian = 0;
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "byteorder must be either 'little' or 'big'");
+ return NULL;
+ }
+
+ if (is_signed_obj != NULL) {
+ int cmp = PyObject_IsTrue(is_signed_obj);
+ if (cmp < 0)
+ return NULL;
+ is_signed = cmp ? 1 : 0;
+ }
+ else {
+ /* If the signed argument was omitted, use False as the
+ default. */
+ is_signed = 0;
+ }
+
+ if (length < 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "length argument must be non-negative");
+ return NULL;
+ }
+
+ bytes = PyBytes_FromStringAndSize(NULL, length);
+ if (bytes == NULL)
+ return NULL;
+
+ if (_PyLong_AsByteArray(v, (unsigned char *)PyBytes_AS_STRING(bytes),
+ length, little_endian, is_signed) < 0) {
+ Py_DECREF(bytes);
+ return NULL;
+ }
+
+ return bytes;
+}
+
+PyDoc_STRVAR(long_from_bytes_doc,
+"int.from_bytes(bytes, byteorder, *, signed=False) -> int\n\
+\n\
+Return the integer represented by the given array of bytes.\n\
+\n\
+The bytes argument must either support the buffer protocol or be an\n\
+iterable object producing bytes. Bytes and bytearray are examples of\n\
+built-in objects that support the buffer protocol.\n\
+\n\
+The byteorder argument determines the byte order used to represent the\n\
+integer. If byteorder is 'big', the most significant byte is at the\n\
+beginning of the byte array. If byteorder is 'little', the most\n\
+significant byte is at the end of the byte array. To request the native\n\
+byte order of the host system, use `sys.byteorder' as the byte order value.\n\
+\n\
+The signed keyword-only argument indicates whether two's complement is\n\
+used to represent the integer.");
+
+static PyObject *
+long_from_bytes(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyObject *byteorder_str;
+ PyObject *is_signed_obj = NULL;
+ int little_endian;
+ int is_signed;
+ PyObject *obj;
+ PyObject *bytes;
+ PyObject *long_obj;
+ static char *kwlist[] = {"bytes", "byteorder", "signed", NULL};
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "OU|O:from_bytes", kwlist,
+ &obj, &byteorder_str,
+ &is_signed_obj))
+ return NULL;
+
+ if (args != NULL && Py_SIZE(args) > 2) {
+ PyErr_SetString(PyExc_TypeError,
+ "'signed' is a keyword-only argument");
+ return NULL;
+ }
+
+ if (!PyUnicode_CompareWithASCIIString(byteorder_str, "little"))
+ little_endian = 1;
+ else if (!PyUnicode_CompareWithASCIIString(byteorder_str, "big"))
+ little_endian = 0;
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "byteorder must be either 'little' or 'big'");
+ return NULL;
+ }
+
+ if (is_signed_obj != NULL) {
+ int cmp = PyObject_IsTrue(is_signed_obj);
+ if (cmp < 0)
+ return NULL;
+ is_signed = cmp ? 1 : 0;
+ }
+ else {
+ /* If the signed argument was omitted, use False as the
+ default. */
+ is_signed = 0;
+ }
+
+ bytes = PyObject_Bytes(obj);
+ if (bytes == NULL)
+ return NULL;
+
+ long_obj = _PyLong_FromByteArray(
+ (unsigned char *)PyBytes_AS_STRING(bytes), Py_SIZE(bytes),
+ little_endian, is_signed);
+ Py_DECREF(bytes);
+
+ /* If from_bytes() was used on subclass, allocate new subclass
+ * instance, initialize it with decoded long value and return it.
+ */
+ if (type != &PyLong_Type && PyType_IsSubtype(type, &PyLong_Type)) {
+ PyLongObject *newobj;
+ int i;
+ Py_ssize_t n = ABS(Py_SIZE(long_obj));
+
+ newobj = (PyLongObject *)type->tp_alloc(type, n);
+ if (newobj == NULL) {
+ Py_DECREF(long_obj);
+ return NULL;
+ }
+ assert(PyLong_Check(newobj));
+ Py_SIZE(newobj) = Py_SIZE(long_obj);
+ for (i = 0; i < n; i++) {
+ newobj->ob_digit[i] =
+ ((PyLongObject *)long_obj)->ob_digit[i];
+ }
+ Py_DECREF(long_obj);
+ return (PyObject *)newobj;
+ }
+
+ return long_obj;
+}
+
static PyMethodDef long_methods[] = {
{"conjugate", (PyCFunction)long_long, METH_NOARGS,
"Returns self, the complex conjugate of any int."},
@@ -4305,6 +4486,10 @@
{"is_finite", (PyCFunction)long_is_finite, METH_NOARGS,
"Returns always True."},
#endif
+ {"to_bytes", (PyCFunction)long_to_bytes,
+ METH_VARARGS|METH_KEYWORDS, long_to_bytes_doc},
+ {"from_bytes", (PyCFunction)long_from_bytes,
+ METH_VARARGS|METH_KEYWORDS|METH_CLASS, long_from_bytes_doc},
{"__trunc__", (PyCFunction)long_long, METH_NOARGS,
"Truncating an Integral returns itself."},
{"__floor__", (PyCFunction)long_long, METH_NOARGS,
Modified: python/branches/py3k-cdecimal/Objects/stringlib/count.h
==============================================================================
--- python/branches/py3k-cdecimal/Objects/stringlib/count.h (original)
+++ python/branches/py3k-cdecimal/Objects/stringlib/count.h Thu Jan 21 20:32:23 2010
@@ -9,28 +9,22 @@
Py_LOCAL_INLINE(Py_ssize_t)
stringlib_count(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
- const STRINGLIB_CHAR* sub, Py_ssize_t sub_len)
+ const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
+ Py_ssize_t maxcount)
{
Py_ssize_t count;
if (str_len < 0)
return 0; /* start > len(str) */
if (sub_len == 0)
- return str_len + 1;
+ return (str_len < maxcount) ? str_len + 1 : maxcount;
- count = fastsearch(str, str_len, sub, sub_len, FAST_COUNT);
+ count = fastsearch(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
if (count < 0)
- count = 0; /* no match */
+ return 0; /* no match */
return count;
}
#endif
-
-/*
-Local variables:
-c-basic-offset: 4
-indent-tabs-mode: nil
-End:
-*/
Modified: python/branches/py3k-cdecimal/Objects/stringlib/ctype.h
==============================================================================
--- python/branches/py3k-cdecimal/Objects/stringlib/ctype.h (original)
+++ python/branches/py3k-cdecimal/Objects/stringlib/ctype.h Thu Jan 21 20:32:23 2010
@@ -107,4 +107,3 @@
STRINGLIB_LEN(self));
return newobj;
}
-
Modified: python/branches/py3k-cdecimal/Objects/stringlib/fastsearch.h
==============================================================================
--- python/branches/py3k-cdecimal/Objects/stringlib/fastsearch.h (original)
+++ python/branches/py3k-cdecimal/Objects/stringlib/fastsearch.h Thu Jan 21 20:32:23 2010
@@ -18,18 +18,33 @@
#define FAST_SEARCH 1
#define FAST_RSEARCH 2
+#if LONG_BIT >= 128
+#define STRINGLIB_BLOOM_WIDTH 128
+#elif LONG_BIT >= 64
+#define STRINGLIB_BLOOM_WIDTH 64
+#elif LONG_BIT >= 32
+#define STRINGLIB_BLOOM_WIDTH 32
+#else
+#error "LONG_BIT is smaller than 32"
+#endif
+
+#define STRINGLIB_BLOOM_ADD(mask, ch) \
+ ((mask |= (1UL << ((ch) & (STRINGLIB_BLOOM_WIDTH -1)))))
+#define STRINGLIB_BLOOM(mask, ch) \
+ ((mask & (1UL << ((ch) & (STRINGLIB_BLOOM_WIDTH -1)))))
+
Py_LOCAL_INLINE(Py_ssize_t)
fastsearch(const STRINGLIB_CHAR* s, Py_ssize_t n,
const STRINGLIB_CHAR* p, Py_ssize_t m,
- int mode)
+ Py_ssize_t maxcount, int mode)
{
- long mask;
+ unsigned long mask;
Py_ssize_t skip, count = 0;
Py_ssize_t i, j, mlast, w;
w = n - m;
- if (w < 0)
+ if (w < 0 || (mode == FAST_COUNT && maxcount == 0))
return -1;
/* look for special cases */
@@ -39,8 +54,11 @@
/* use special case for 1-character strings */
if (mode == FAST_COUNT) {
for (i = 0; i < n; i++)
- if (s[i] == p[0])
+ if (s[i] == p[0]) {
count++;
+ if (count == maxcount)
+ return maxcount;
+ }
return count;
} else if (mode == FAST_SEARCH) {
for (i = 0; i < n; i++)
@@ -56,19 +74,20 @@
mlast = m - 1;
skip = mlast - 1;
+ mask = 0;
if (mode != FAST_RSEARCH) {
/* create compressed boyer-moore delta 1 table */
/* process pattern[:-1] */
- for (mask = i = 0; i < mlast; i++) {
- mask |= (1 << (p[i] & 0x1F));
+ for (i = 0; i < mlast; i++) {
+ STRINGLIB_BLOOM_ADD(mask, p[i]);
if (p[i] == p[mlast])
skip = mlast - i - 1;
}
/* process pattern[-1] outside the loop */
- mask |= (1 << (p[mlast] & 0x1F));
+ STRINGLIB_BLOOM_ADD(mask, p[mlast]);
for (i = 0; i <= w; i++) {
/* note: using mlast in the skip path slows things down on x86 */
@@ -82,17 +101,19 @@
if (mode != FAST_COUNT)
return i;
count++;
+ if (count == maxcount)
+ return maxcount;
i = i + mlast;
continue;
}
/* miss: check if next character is part of pattern */
- if (!(mask & (1 << (s[i+m] & 0x1F))))
+ if (!STRINGLIB_BLOOM(mask, s[i+m]))
i = i + m;
else
i = i + skip;
} else {
/* skip: check if next character is part of pattern */
- if (!(mask & (1 << (s[i+m] & 0x1F))))
+ if (!STRINGLIB_BLOOM(mask, s[i+m]))
i = i + m;
}
}
@@ -101,10 +122,10 @@
/* create compressed boyer-moore delta 1 table */
/* process pattern[0] outside the loop */
- mask = (1 << (p[0] & 0x1F));
+ STRINGLIB_BLOOM_ADD(mask, p[0]);
/* process pattern[:0:-1] */
for (i = mlast; i > 0; i--) {
- mask |= (1 << (p[i] & 0x1F));
+ STRINGLIB_BLOOM_ADD(mask, p[i]);
if (p[i] == p[0])
skip = i - 1;
}
@@ -119,13 +140,13 @@
/* got a match! */
return i;
/* miss: check if previous character is part of pattern */
- if (!(mask & (1 << (s[i-1] & 0x1F))))
+ if (!STRINGLIB_BLOOM(mask, s[i-1]))
i = i - m;
else
i = i - skip;
} else {
/* skip: check if previous character is part of pattern */
- if (!(mask & (1 << (s[i-1] & 0x1F))))
+ if (!STRINGLIB_BLOOM(mask, s[i-1]))
i = i - m;
}
}
@@ -137,10 +158,3 @@
}
#endif
-
-/*
-Local variables:
-c-basic-offset: 4
-indent-tabs-mode: nil
-End:
-*/
Modified: python/branches/py3k-cdecimal/Objects/stringlib/find.h
==============================================================================
--- python/branches/py3k-cdecimal/Objects/stringlib/find.h (original)
+++ python/branches/py3k-cdecimal/Objects/stringlib/find.h Thu Jan 21 20:32:23 2010
@@ -19,7 +19,7 @@
if (sub_len == 0)
return offset;
- pos = fastsearch(str, str_len, sub, sub_len, FAST_SEARCH);
+ pos = fastsearch(str, str_len, sub, sub_len, -1, FAST_SEARCH);
if (pos >= 0)
pos += offset;
@@ -39,7 +39,7 @@
if (sub_len == 0)
return str_len + offset;
- pos = fastsearch(str, str_len, sub, sub_len, FAST_RSEARCH);
+ pos = fastsearch(str, str_len, sub, sub_len, -1, FAST_RSEARCH);
if (pos >= 0)
pos += offset;
@@ -47,22 +47,27 @@
return pos;
}
+/* helper macro to fixup start/end slice values */
+#define ADJUST_INDICES(start, end, len) \
+ if (end > len) \
+ end = len; \
+ else if (end < 0) { \
+ end += len; \
+ if (end < 0) \
+ end = 0; \
+ } \
+ if (start < 0) { \
+ start += len; \
+ if (start < 0) \
+ start = 0; \
+ }
+
Py_LOCAL_INLINE(Py_ssize_t)
stringlib_find_slice(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
Py_ssize_t start, Py_ssize_t end)
{
- if (start < 0)
- start += str_len;
- if (start < 0)
- start = 0;
- if (end > str_len)
- end = str_len;
- if (end < 0)
- end += str_len;
- if (end < 0)
- end = 0;
-
+ ADJUST_INDICES(start, end, str_len);
return stringlib_find(str + start, end - start, sub, sub_len, start);
}
@@ -71,17 +76,7 @@
const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
Py_ssize_t start, Py_ssize_t end)
{
- if (start < 0)
- start += str_len;
- if (start < 0)
- start = 0;
- if (end > str_len)
- end = str_len;
- if (end < 0)
- end += str_len;
- if (end < 0)
- end = 0;
-
+ ADJUST_INDICES(start, end, str_len);
return stringlib_rfind(str + start, end - start, sub, sub_len, start);
}
@@ -96,9 +91,9 @@
) != -1;
}
-#endif /* STRINGLIB_STR */
+#endif /* STRINGLIB_WANT_CONTAINS_OBJ */
-#ifdef FROM_UNICODE
+#if STRINGLIB_IS_UNICODE
/*
This function is a helper for the "find" family (find, rfind, index,
@@ -146,13 +141,6 @@
return 1;
}
-#endif /* FROM_UNICODE */
+#endif /* STRINGLIB_IS_UNICODE */
#endif /* STRINGLIB_FIND_H */
-
-/*
-Local variables:
-c-basic-offset: 4
-indent-tabs-mode: nil
-End:
-*/
Modified: python/branches/py3k-cdecimal/Objects/stringlib/partition.h
==============================================================================
--- python/branches/py3k-cdecimal/Objects/stringlib/partition.h (original)
+++ python/branches/py3k-cdecimal/Objects/stringlib/partition.h Thu Jan 21 20:32:23 2010
@@ -8,33 +8,39 @@
#endif
Py_LOCAL_INLINE(PyObject*)
-stringlib_partition(
- PyObject* str_obj, const STRINGLIB_CHAR* str, Py_ssize_t str_len,
- PyObject* sep_obj, const STRINGLIB_CHAR* sep, Py_ssize_t sep_len
- )
+stringlib_partition(PyObject* str_obj,
+ const STRINGLIB_CHAR* str, Py_ssize_t str_len,
+ PyObject* sep_obj,
+ const STRINGLIB_CHAR* sep, Py_ssize_t sep_len)
{
PyObject* out;
Py_ssize_t pos;
if (sep_len == 0) {
PyErr_SetString(PyExc_ValueError, "empty separator");
- return NULL;
+ return NULL;
}
out = PyTuple_New(3);
if (!out)
- return NULL;
+ return NULL;
- pos = fastsearch(str, str_len, sep, sep_len, FAST_SEARCH);
+ pos = fastsearch(str, str_len, sep, sep_len, -1, FAST_SEARCH);
if (pos < 0) {
- Py_INCREF(str_obj);
- PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj);
- Py_INCREF(STRINGLIB_EMPTY);
- PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY);
- Py_INCREF(STRINGLIB_EMPTY);
- PyTuple_SET_ITEM(out, 2, (PyObject*) STRINGLIB_EMPTY);
- return out;
+#if STRINGLIB_MUTABLE
+ PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, str_len));
+ PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0));
+ PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(NULL, 0));
+#else
+ Py_INCREF(str_obj);
+ PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj);
+ Py_INCREF(STRINGLIB_EMPTY);
+ PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY);
+ Py_INCREF(STRINGLIB_EMPTY);
+ PyTuple_SET_ITEM(out, 2, (PyObject*) STRINGLIB_EMPTY);
+#endif
+ return out;
}
PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos));
@@ -44,41 +50,47 @@
PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos));
if (PyErr_Occurred()) {
- Py_DECREF(out);
- return NULL;
+ Py_DECREF(out);
+ return NULL;
}
return out;
}
Py_LOCAL_INLINE(PyObject*)
-stringlib_rpartition(
- PyObject* str_obj, const STRINGLIB_CHAR* str, Py_ssize_t str_len,
- PyObject* sep_obj, const STRINGLIB_CHAR* sep, Py_ssize_t sep_len
- )
+stringlib_rpartition(PyObject* str_obj,
+ const STRINGLIB_CHAR* str, Py_ssize_t str_len,
+ PyObject* sep_obj,
+ const STRINGLIB_CHAR* sep, Py_ssize_t sep_len)
{
PyObject* out;
Py_ssize_t pos;
if (sep_len == 0) {
PyErr_SetString(PyExc_ValueError, "empty separator");
- return NULL;
+ return NULL;
}
out = PyTuple_New(3);
if (!out)
- return NULL;
+ return NULL;
- pos = fastsearch(str, str_len, sep, sep_len, FAST_RSEARCH);
+ pos = fastsearch(str, str_len, sep, sep_len, -1, FAST_RSEARCH);
if (pos < 0) {
- Py_INCREF(STRINGLIB_EMPTY);
- PyTuple_SET_ITEM(out, 0, (PyObject*) STRINGLIB_EMPTY);
- Py_INCREF(STRINGLIB_EMPTY);
- PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY);
- Py_INCREF(str_obj);
- PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj);
- return out;
+#if STRINGLIB_MUTABLE
+ PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(NULL, 0));
+ PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0));
+ PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str, str_len));
+#else
+ Py_INCREF(STRINGLIB_EMPTY);
+ PyTuple_SET_ITEM(out, 0, (PyObject*) STRINGLIB_EMPTY);
+ Py_INCREF(STRINGLIB_EMPTY);
+ PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY);
+ Py_INCREF(str_obj);
+ PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj);
+#endif
+ return out;
}
PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos));
@@ -88,18 +100,11 @@
PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos));
if (PyErr_Occurred()) {
- Py_DECREF(out);
- return NULL;
+ Py_DECREF(out);
+ return NULL;
}
return out;
}
#endif
-
-/*
-Local variables:
-c-basic-offset: 4
-indent-tabs-mode: nil
-End:
-*/
Modified: python/branches/py3k-cdecimal/Objects/stringlib/stringdefs.h
==============================================================================
--- python/branches/py3k-cdecimal/Objects/stringlib/stringdefs.h (original)
+++ python/branches/py3k-cdecimal/Objects/stringlib/stringdefs.h Thu Jan 21 20:32:23 2010
@@ -11,6 +11,8 @@
#define STRINGLIB_TYPE_NAME "string"
#define STRINGLIB_PARSE_CODE "S"
#define STRINGLIB_EMPTY nullstring
+#define STRINGLIB_ISSPACE Py_ISSPACE
+#define STRINGLIB_ISLINEBREAK(x) ((x == '\n') || (x == '\r'))
#define STRINGLIB_ISDECIMAL(x) ((x >= '0') && (x <= '9'))
#define STRINGLIB_TODECIMAL(x) (STRINGLIB_ISDECIMAL(x) ? (x - '0') : -1)
#define STRINGLIB_TOUPPER Py_TOUPPER
Modified: python/branches/py3k-cdecimal/Objects/stringlib/transmogrify.h
==============================================================================
--- python/branches/py3k-cdecimal/Objects/stringlib/transmogrify.h (original)
+++ python/branches/py3k-cdecimal/Objects/stringlib/transmogrify.h Thu Jan 21 20:32:23 2010
@@ -1,13 +1,6 @@
/* NOTE: this API is -ONLY- for use with single byte character strings. */
/* Do not use it with Unicode. */
-#include "bytes_methods.h"
-
-#ifndef STRINGLIB_MUTABLE
-#warning "STRINGLIB_MUTABLE not defined before #include, assuming 0"
-#define STRINGLIB_MUTABLE 0
-#endif
-
/* the more complicated methods. parts of these should be pulled out into the
shared code in bytes_methods.c to cut down on duplicate code bloat. */
@@ -269,87 +262,3 @@
return (PyObject*) s;
}
-
-
-#define _STRINGLIB_SPLIT_APPEND(data, left, right) \
- str = STRINGLIB_NEW((data) + (left), \
- (right) - (left)); \
- if (str == NULL) \
- goto onError; \
- if (PyList_Append(list, str)) { \
- Py_DECREF(str); \
- goto onError; \
- } \
- else \
- Py_DECREF(str);
-
-PyDoc_STRVAR(splitlines__doc__,
-"B.splitlines([keepends]) -> list of lines\n\
-\n\
-Return a list of the lines in B, breaking at line boundaries.\n\
-Line breaks are not included in the resulting list unless keepends\n\
-is given and true.");
-
-static PyObject*
-stringlib_splitlines(PyObject *self, PyObject *args)
-{
- register Py_ssize_t i;
- register Py_ssize_t j;
- Py_ssize_t len;
- int keepends = 0;
- PyObject *list;
- PyObject *str;
- char *data;
-
- if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends))
- return NULL;
-
- data = STRINGLIB_STR(self);
- len = STRINGLIB_LEN(self);
-
- /* This does not use the preallocated list because splitlines is
- usually run with hundreds of newlines. The overhead of
- switching between PyList_SET_ITEM and append causes about a
- 2-3% slowdown for that common case. A smarter implementation
- could move the if check out, so the SET_ITEMs are done first
- and the appends only done when the prealloc buffer is full.
- That's too much work for little gain.*/
-
- list = PyList_New(0);
- if (!list)
- goto onError;
-
- for (i = j = 0; i < len; ) {
- Py_ssize_t eol;
-
- /* Find a line and append it */
- while (i < len && data[i] != '\n' && data[i] != '\r')
- i++;
-
- /* Skip the line break reading CRLF as one line break */
- eol = i;
- if (i < len) {
- if (data[i] == '\r' && i + 1 < len &&
- data[i+1] == '\n')
- i += 2;
- else
- i++;
- if (keepends)
- eol = i;
- }
- _STRINGLIB_SPLIT_APPEND(data, j, eol);
- j = i;
- }
- if (j < len) {
- _STRINGLIB_SPLIT_APPEND(data, j, len);
- }
-
- return list;
-
- onError:
- Py_XDECREF(list);
- return NULL;
-}
-
-#undef _STRINGLIB_SPLIT_APPEND
-
Modified: python/branches/py3k-cdecimal/Objects/stringlib/unicodedefs.h
==============================================================================
--- python/branches/py3k-cdecimal/Objects/stringlib/unicodedefs.h (original)
+++ python/branches/py3k-cdecimal/Objects/stringlib/unicodedefs.h Thu Jan 21 20:32:23 2010
@@ -11,6 +11,8 @@
#define STRINGLIB_TYPE_NAME "unicode"
#define STRINGLIB_PARSE_CODE "U"
#define STRINGLIB_EMPTY unicode_empty
+#define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE
+#define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK
#define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL
#define STRINGLIB_TODECIMAL Py_UNICODE_TODECIMAL
#define STRINGLIB_TOUPPER Py_UNICODE_TOUPPER
Modified: python/branches/py3k-cdecimal/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k-cdecimal/Objects/unicodeobject.c (original)
+++ python/branches/py3k-cdecimal/Objects/unicodeobject.c Thu Jan 21 20:32:23 2010
@@ -206,11 +206,22 @@
/* the linebreak mask is set up by Unicode_Init below */
+#if LONG_BIT >= 128
+#define BLOOM_WIDTH 128
+#elif LONG_BIT >= 64
+#define BLOOM_WIDTH 64
+#elif LONG_BIT >= 32
+#define BLOOM_WIDTH 32
+#else
+#error "LONG_BIT is smaller than 32"
+#endif
+
#define BLOOM_MASK unsigned long
static BLOOM_MASK bloom_linebreak;
-#define BLOOM(mask, ch) ((mask & (1 << ((ch) & 0x1F))))
+#define BLOOM_ADD(mask, ch) ((mask |= (1UL << ((ch) & (BLOOM_WIDTH - 1)))))
+#define BLOOM(mask, ch) ((mask & (1UL << ((ch) & (BLOOM_WIDTH - 1)))))
#define BLOOM_LINEBREAK(ch) \
((ch) < 128U ? ascii_linebreak[(ch)] : \
@@ -220,12 +231,12 @@
{
/* calculate simple bloom-style bitmask for a given unicode string */
- long mask;
+ BLOOM_MASK mask;
Py_ssize_t i;
mask = 0;
for (i = 0; i < len; i++)
- mask |= (1 << (ptr[i] & 0x1F));
+ BLOOM_ADD(mask, ptr[i]);
return mask;
}
@@ -5873,28 +5884,30 @@
#include "stringlib/unicodedefs.h"
#include "stringlib/fastsearch.h"
+
#include "stringlib/count.h"
-/* Include _ParseTupleFinds from find.h */
-#define FROM_UNICODE
#include "stringlib/find.h"
#include "stringlib/partition.h"
+#include "stringlib/split.h"
#define _Py_InsertThousandsGrouping _PyUnicode_InsertThousandsGrouping
#define _Py_InsertThousandsGroupingLocale _PyUnicode_InsertThousandsGroupingLocale
#include "stringlib/localeutil.h"
/* helper macro to fixup start/end slice values */
-#define FIX_START_END(obj) \
- if (start < 0) \
- start += (obj)->length; \
- if (start < 0) \
- start = 0; \
- if (end > (obj)->length) \
- end = (obj)->length; \
- if (end < 0) \
- end += (obj)->length; \
- if (end < 0) \
- end = 0;
+#define ADJUST_INDICES(start, end, len) \
+ if (end > len) \
+ end = len; \
+ else if (end < 0) { \
+ end += len; \
+ if (end < 0) \
+ end = 0; \
+ } \
+ if (start < 0) { \
+ start += len; \
+ if (start < 0) \
+ start = 0; \
+ }
Py_ssize_t PyUnicode_Count(PyObject *str,
PyObject *substr,
@@ -5914,10 +5927,10 @@
return -1;
}
- FIX_START_END(str_obj);
-
+ ADJUST_INDICES(start, end, str_obj->length);
result = stringlib_count(
- str_obj->str + start, end - start, sub_obj->str, sub_obj->length
+ str_obj->str + start, end - start, sub_obj->str, sub_obj->length,
+ PY_SSIZE_T_MAX
);
Py_DECREF(sub_obj);
@@ -5972,8 +5985,7 @@
if (substring->length == 0)
return 1;
- FIX_START_END(self);
-
+ ADJUST_INDICES(start, end, self->length);
end -= substring->length;
if (end < start)
return 0;
@@ -6314,305 +6326,40 @@
return u;
}
-#define SPLIT_APPEND(data, left, right) \
- str = PyUnicode_FromUnicode((data) + (left), (right) - (left)); \
- if (!str) \
- goto onError; \
- if (PyList_Append(list, str)) { \
- Py_DECREF(str); \
- goto onError; \
- } \
- else \
- Py_DECREF(str);
-
-static
-PyObject *split_whitespace(PyUnicodeObject *self,
- PyObject *list,
- Py_ssize_t maxcount)
+PyObject *PyUnicode_Splitlines(PyObject *string, int keepends)
{
- register Py_ssize_t i;
- register Py_ssize_t j;
- Py_ssize_t len = self->length;
- PyObject *str;
- register const Py_UNICODE *buf = self->str;
-
- for (i = j = 0; i < len; ) {
- /* find a token */
- while (i < len && Py_UNICODE_ISSPACE(buf[i]))
- i++;
- j = i;
- while (i < len && !Py_UNICODE_ISSPACE(buf[i]))
- i++;
- if (j < i) {
- if (maxcount-- <= 0)
- break;
- SPLIT_APPEND(buf, j, i);
- while (i < len && Py_UNICODE_ISSPACE(buf[i]))
- i++;
- j = i;
- }
- }
- if (j < len) {
- SPLIT_APPEND(buf, j, len);
- }
- return list;
-
- onError:
- Py_DECREF(list);
- return NULL;
-}
-
-PyObject *PyUnicode_Splitlines(PyObject *string,
- int keepends)
-{
- register Py_ssize_t i;
- register Py_ssize_t j;
- Py_ssize_t len;
PyObject *list;
- PyObject *str;
- Py_UNICODE *data;
string = PyUnicode_FromObject(string);
if (string == NULL)
return NULL;
- data = PyUnicode_AS_UNICODE(string);
- len = PyUnicode_GET_SIZE(string);
- list = PyList_New(0);
- if (!list)
- goto onError;
+ list = stringlib_splitlines(
+ (PyObject*) string, PyUnicode_AS_UNICODE(string),
+ PyUnicode_GET_SIZE(string), keepends);
- for (i = j = 0; i < len; ) {
- Py_ssize_t eol;
-
- /* Find a line and append it */
- while (i < len && !BLOOM_LINEBREAK(data[i]))
- i++;
-
- /* Skip the line break reading CRLF as one line break */
- eol = i;
- if (i < len) {
- if (data[i] == '\r' && i + 1 < len &&
- data[i+1] == '\n')
- i += 2;
- else
- i++;
- if (keepends)
- eol = i;
- }
- SPLIT_APPEND(data, j, eol);
- j = i;
- }
- if (j < len) {
- SPLIT_APPEND(data, j, len);
- }
-
- Py_DECREF(string);
- return list;
-
- onError:
- Py_XDECREF(list);
Py_DECREF(string);
- return NULL;
-}
-
-static
-PyObject *split_char(PyUnicodeObject *self,
- PyObject *list,
- Py_UNICODE ch,
- Py_ssize_t maxcount)
-{
- register Py_ssize_t i;
- register Py_ssize_t j;
- Py_ssize_t len = self->length;
- PyObject *str;
- register const Py_UNICODE *buf = self->str;
-
- for (i = j = 0; i < len; ) {
- if (buf[i] == ch) {
- if (maxcount-- <= 0)
- break;
- SPLIT_APPEND(buf, j, i);
- i = j = i + 1;
- } else
- i++;
- }
- if (j <= len) {
- SPLIT_APPEND(buf, j, len);
- }
return list;
-
- onError:
- Py_DECREF(list);
- return NULL;
}
static
-PyObject *split_substring(PyUnicodeObject *self,
- PyObject *list,
- PyUnicodeObject *substring,
- Py_ssize_t maxcount)
-{
- register Py_ssize_t i;
- register Py_ssize_t j;
- Py_ssize_t len = self->length;
- Py_ssize_t sublen = substring->length;
- PyObject *str;
-
- for (i = j = 0; i <= len - sublen; ) {
- if (Py_UNICODE_MATCH(self, i, substring)) {
- if (maxcount-- <= 0)
- break;
- SPLIT_APPEND(self->str, j, i);
- i = j = i + sublen;
- } else
- i++;
- }
- if (j <= len) {
- SPLIT_APPEND(self->str, j, len);
- }
- return list;
-
- onError:
- Py_DECREF(list);
- return NULL;
-}
-
-static
-PyObject *rsplit_whitespace(PyUnicodeObject *self,
- PyObject *list,
- Py_ssize_t maxcount)
-{
- register Py_ssize_t i;
- register Py_ssize_t j;
- Py_ssize_t len = self->length;
- PyObject *str;
- register const Py_UNICODE *buf = self->str;
-
- for (i = j = len - 1; i >= 0; ) {
- /* find a token */
- while (i >= 0 && Py_UNICODE_ISSPACE(buf[i]))
- i--;
- j = i;
- while (i >= 0 && !Py_UNICODE_ISSPACE(buf[i]))
- i--;
- if (j > i) {
- if (maxcount-- <= 0)
- break;
- SPLIT_APPEND(buf, i + 1, j + 1);
- while (i >= 0 && Py_UNICODE_ISSPACE(buf[i]))
- i--;
- j = i;
- }
- }
- if (j >= 0) {
- SPLIT_APPEND(buf, 0, j + 1);
- }
- if (PyList_Reverse(list) < 0)
- goto onError;
- return list;
-
- onError:
- Py_DECREF(list);
- return NULL;
-}
-
-static
-PyObject *rsplit_char(PyUnicodeObject *self,
- PyObject *list,
- Py_UNICODE ch,
- Py_ssize_t maxcount)
-{
- register Py_ssize_t i;
- register Py_ssize_t j;
- Py_ssize_t len = self->length;
- PyObject *str;
- register const Py_UNICODE *buf = self->str;
-
- for (i = j = len - 1; i >= 0; ) {
- if (buf[i] == ch) {
- if (maxcount-- <= 0)
- break;
- SPLIT_APPEND(buf, i + 1, j + 1);
- j = i = i - 1;
- } else
- i--;
- }
- if (j >= -1) {
- SPLIT_APPEND(buf, 0, j + 1);
- }
- if (PyList_Reverse(list) < 0)
- goto onError;
- return list;
-
- onError:
- Py_DECREF(list);
- return NULL;
-}
-
-static
-PyObject *rsplit_substring(PyUnicodeObject *self,
- PyObject *list,
- PyUnicodeObject *substring,
- Py_ssize_t maxcount)
-{
- register Py_ssize_t i;
- register Py_ssize_t j;
- Py_ssize_t len = self->length;
- Py_ssize_t sublen = substring->length;
- PyObject *str;
-
- for (i = len - sublen, j = len; i >= 0; ) {
- if (Py_UNICODE_MATCH(self, i, substring)) {
- if (maxcount-- <= 0)
- break;
- SPLIT_APPEND(self->str, i + sublen, j);
- j = i;
- i -= sublen;
- } else
- i--;
- }
- if (j >= 0) {
- SPLIT_APPEND(self->str, 0, j);
- }
- if (PyList_Reverse(list) < 0)
- goto onError;
- return list;
-
- onError:
- Py_DECREF(list);
- return NULL;
-}
-
-#undef SPLIT_APPEND
-
-static
PyObject *split(PyUnicodeObject *self,
PyUnicodeObject *substring,
Py_ssize_t maxcount)
{
- PyObject *list;
-
if (maxcount < 0)
maxcount = PY_SSIZE_T_MAX;
- list = PyList_New(0);
- if (!list)
- return NULL;
-
if (substring == NULL)
- return split_whitespace(self,list,maxcount);
-
- else if (substring->length == 1)
- return split_char(self,list,substring->str[0],maxcount);
+ return stringlib_split_whitespace(
+ (PyObject*) self, self->str, self->length, maxcount
+ );
- else if (substring->length == 0) {
- Py_DECREF(list);
- PyErr_SetString(PyExc_ValueError, "empty separator");
- return NULL;
- }
- else
- return split_substring(self,list,substring,maxcount);
+ return stringlib_split(
+ (PyObject*) self, self->str, self->length,
+ substring->str, substring->length,
+ maxcount
+ );
}
static
@@ -6620,28 +6367,19 @@
PyUnicodeObject *substring,
Py_ssize_t maxcount)
{
- PyObject *list;
-
if (maxcount < 0)
maxcount = PY_SSIZE_T_MAX;
- list = PyList_New(0);
- if (!list)
- return NULL;
-
if (substring == NULL)
- return rsplit_whitespace(self,list,maxcount);
-
- else if (substring->length == 1)
- return rsplit_char(self,list,substring->str[0],maxcount);
+ return stringlib_rsplit_whitespace(
+ (PyObject*) self, self->str, self->length, maxcount
+ );
- else if (substring->length == 0) {
- Py_DECREF(list);
- PyErr_SetString(PyExc_ValueError, "empty separator");
- return NULL;
- }
- else
- return rsplit_substring(self,list,substring,maxcount);
+ return stringlib_rsplit(
+ (PyObject*) self, self->str, self->length,
+ substring->str, substring->length,
+ maxcount
+ );
}
static
@@ -6654,10 +6392,14 @@
if (maxcount < 0)
maxcount = PY_SSIZE_T_MAX;
+ else if (maxcount == 0 || self->length == 0)
+ goto nothing;
if (str1->length == str2->length) {
- /* same length */
Py_ssize_t i;
+ /* same length */
+ if (str1->length == 0)
+ goto nothing;
if (str1->length == 1) {
/* replace characters */
Py_UNICODE u1, u2;
@@ -6676,8 +6418,8 @@
u->str[i] = u2;
}
} else {
- i = fastsearch(
- self->str, self->length, str1->str, str1->length, FAST_SEARCH
+ i = stringlib_find(
+ self->str, self->length, str1->str, str1->length, 0
);
if (i < 0)
goto nothing;
@@ -6685,14 +6427,20 @@
if (!u)
return NULL;
Py_UNICODE_COPY(u->str, self->str, self->length);
- while (i <= self->length - str1->length)
- if (Py_UNICODE_MATCH(self, i, str1)) {
- if (--maxcount < 0)
- break;
- Py_UNICODE_COPY(u->str+i, str2->str, str2->length);
- i += str1->length;
- } else
- i++;
+
+ /* change everything in-place, starting with this one */
+ Py_UNICODE_COPY(u->str+i, str2->str, str2->length);
+ i += str1->length;
+
+ while ( --maxcount > 0) {
+ i = stringlib_find(self->str+i, self->length-i,
+ str1->str, str1->length,
+ i);
+ if (i == -1)
+ break;
+ Py_UNICODE_COPY(u->str+i, str2->str, str2->length);
+ i += str1->length;
+ }
}
} else {
@@ -6701,9 +6449,8 @@
Py_UNICODE *p;
/* replace strings */
- n = stringlib_count(self->str, self->length, str1->str, str1->length);
- if (n > maxcount)
- n = maxcount;
+ n = stringlib_count(self->str, self->length, str1->str, str1->length,
+ maxcount);
if (n == 0)
goto nothing;
/* new_size = self->length + n * (str2->length - str1->length)); */
@@ -6733,15 +6480,12 @@
if (str1->length > 0) {
while (n-- > 0) {
/* look for next match */
- j = i;
- while (j <= e) {
- if (Py_UNICODE_MATCH(self, j, str1))
- break;
- j++;
- }
- if (j > i) {
- if (j > e)
- break;
+ j = stringlib_find(self->str+i, self->length-i,
+ str1->str, str1->length,
+ i);
+ if (j == -1)
+ break;
+ else if (j > i) {
/* copy unchanged part [i:j] */
Py_UNICODE_COPY(p, self->str+i, j-i);
p += j - i;
@@ -7001,6 +6745,11 @@
for (i = 0; id[i] && str[i]; i++)
if (id[i] != str[i])
return ((int)id[i] < (int)str[i]) ? -1 : 1;
+ /* This check keeps Python strings that end in '\0' from comparing equal
+ to C strings identical up to that point. */
+ if (PyUnicode_GET_SIZE(uni) != i)
+ /* We'll say the Python string is longer. */
+ return 1;
if (id[i])
return 1; /* uni is longer */
if (str[i])
@@ -7187,11 +6936,11 @@
if (substring == NULL)
return NULL;
- FIX_START_END(self);
-
+ ADJUST_INDICES(start, end, self->length);
result = PyLong_FromSsize_t(
stringlib_count(self->str + start, end - start,
- substring->str, substring->length)
+ substring->str, substring->length,
+ PY_SSIZE_T_MAX)
);
Py_DECREF(substring);
@@ -10061,11 +9810,3 @@
#ifdef __cplusplus
}
#endif
-
-
-/*
- Local variables:
- c-basic-offset: 4
- indent-tabs-mode: nil
- End:
-*/
Modified: python/branches/py3k-cdecimal/PC/VS8.0/pythoncore.vcproj
==============================================================================
--- python/branches/py3k-cdecimal/PC/VS8.0/pythoncore.vcproj (original)
+++ python/branches/py3k-cdecimal/PC/VS8.0/pythoncore.vcproj Thu Jan 21 20:32:23 2010
@@ -1491,6 +1491,10 @@
>
</File>
<File
+ RelativePath="..\..\Objects\stringlib\split.h"
+ >
+ </File>
+ <File
RelativePath="..\..\Objects\structseq.c"
>
</File>
Modified: python/branches/py3k-cdecimal/PCbuild/pythoncore.vcproj
==============================================================================
--- python/branches/py3k-cdecimal/PCbuild/pythoncore.vcproj (original)
+++ python/branches/py3k-cdecimal/PCbuild/pythoncore.vcproj Thu Jan 21 20:32:23 2010
@@ -1496,6 +1496,10 @@
>
</File>
<File
+ RelativePath="..\Objects\stringlib\split.h"
+ >
+ </File>
+ <File
RelativePath="..\Objects\structseq.c"
>
</File>
Modified: python/branches/py3k-cdecimal/Python/dtoa.c
==============================================================================
--- python/branches/py3k-cdecimal/Python/dtoa.c (original)
+++ python/branches/py3k-cdecimal/Python/dtoa.c Thu Jan 21 20:32:23 2010
@@ -200,10 +200,11 @@
#define STRTOD_DIGLIM 40
#endif
-#ifdef DIGLIM_DEBUG
-extern int strtod_diglim;
-#else
-#define strtod_diglim STRTOD_DIGLIM
+/* maximum permitted exponent value for strtod; exponents larger than
+ MAX_ABS_EXP in absolute value get truncated to +-MAX_ABS_EXP. MAX_ABS_EXP
+ should fit into an int. */
+#ifndef MAX_ABS_EXP
+#define MAX_ABS_EXP 19999U
#endif
/* The following definition of Storeinc is appropriate for MIPS processors.
@@ -269,8 +270,7 @@
typedef struct BCinfo BCinfo;
struct
BCinfo {
- int dp0, dp1, dplen, dsign, e0, inexact;
- int nd, nd0, rounding, scale, uflchk;
+ int dsign, e0, nd, nd0, scale;
};
#define FFFFFFFF 0xffffffffUL
@@ -308,6 +308,8 @@
typedef struct Bigint Bigint;
+#ifndef Py_USING_MEMORY_DEBUGGER
+
/* Memory management: memory is allocated from, and returned to, Kmax+1 pools
of memory, where pool k (0 <= k <= Kmax) is for Bigints b with b->maxwds ==
1 << k. These pools are maintained as linked lists, with freelist[k]
@@ -375,6 +377,48 @@
}
}
+#else
+
+/* Alternative versions of Balloc and Bfree that use PyMem_Malloc and
+ PyMem_Free directly in place of the custom memory allocation scheme above.
+ These are provided for the benefit of memory debugging tools like
+ Valgrind. */
+
+/* Allocate space for a Bigint with up to 1<<k digits */
+
+static Bigint *
+Balloc(int k)
+{
+ int x;
+ Bigint *rv;
+ unsigned int len;
+
+ x = 1 << k;
+ len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
+ /sizeof(double);
+
+ rv = (Bigint*)MALLOC(len*sizeof(double));
+ if (rv == NULL)
+ return NULL;
+
+ rv->k = k;
+ rv->maxwds = x;
+ rv->sign = rv->wds = 0;
+ return rv;
+}
+
+/* Free a Bigint allocated with Balloc */
+
+static void
+Bfree(Bigint *v)
+{
+ if (v) {
+ FREE((void*)v);
+ }
+}
+
+#endif /* Py_USING_MEMORY_DEBUGGER */
+
#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \
y->wds*sizeof(Long) + 2*sizeof(int))
@@ -437,7 +481,7 @@
NULL on failure. */
static Bigint *
-s2b(const char *s, int nd0, int nd, ULong y9, int dplen)
+s2b(const char *s, int nd0, int nd, ULong y9)
{
Bigint *b;
int i, k;
@@ -451,18 +495,16 @@
b->x[0] = y9;
b->wds = 1;
- i = 9;
- if (9 < nd0) {
- s += 9;
- do {
- b = multadd(b, 10, *s++ - '0');
- if (b == NULL)
- return NULL;
- } while(++i < nd0);
- s += dplen;
+ if (nd <= 9)
+ return b;
+
+ s += 9;
+ for (i = 9; i < nd0; i++) {
+ b = multadd(b, 10, *s++ - '0');
+ if (b == NULL)
+ return NULL;
}
- else
- s += dplen + 9;
+ s++;
for(; i < nd; i++) {
b = multadd(b, 10, *s++ - '0');
if (b == NULL)
@@ -654,6 +696,8 @@
return c;
}
+#ifndef Py_USING_MEMORY_DEBUGGER
+
/* p5s is a linked list of powers of 5 of the form 5**(2**i), i >= 2 */
static Bigint *p5s;
@@ -713,6 +757,58 @@
return b;
}
+#else
+
+/* Version of pow5mult that doesn't cache powers of 5. Provided for
+ the benefit of memory debugging tools like Valgrind. */
+
+static Bigint *
+pow5mult(Bigint *b, int k)
+{
+ Bigint *b1, *p5, *p51;
+ int i;
+ static int p05[3] = { 5, 25, 125 };
+
+ if ((i = k & 3)) {
+ b = multadd(b, p05[i-1], 0);
+ if (b == NULL)
+ return NULL;
+ }
+
+ if (!(k >>= 2))
+ return b;
+ p5 = i2b(625);
+ if (p5 == NULL) {
+ Bfree(b);
+ return NULL;
+ }
+
+ for(;;) {
+ if (k & 1) {
+ b1 = mult(b, p5);
+ Bfree(b);
+ b = b1;
+ if (b == NULL) {
+ Bfree(p5);
+ return NULL;
+ }
+ }
+ if (!(k >>= 1))
+ break;
+ p51 = mult(p5, p5);
+ Bfree(p5);
+ p5 = p51;
+ if (p5 == NULL) {
+ Bfree(b);
+ return NULL;
+ }
+ }
+ Bfree(p5);
+ return b;
+}
+
+#endif /* Py_USING_MEMORY_DEBUGGER */
+
/* shift a Bigint b left by k bits. Return a pointer to the shifted result,
or NULL on failure. If the returned pointer is distinct from b then the
original b will have been Bfree'd. Ignores the sign of b. */
@@ -1130,56 +1226,120 @@
return q;
}
+/* sulp(x) is a version of ulp(x) that takes bc.scale into account.
+
+ Assuming that x is finite and nonnegative (positive zero is fine
+ here) and x / 2^bc.scale is exactly representable as a double,
+ sulp(x) is equivalent to 2^bc.scale * ulp(x / 2^bc.scale). */
+
+static double
+sulp(U *x, BCinfo *bc)
+{
+ U u;
+
+ if (bc->scale && 2*P + 1 > (int)((word0(x) & Exp_mask) >> Exp_shift)) {
+ /* rv/2^bc->scale is subnormal */
+ word0(&u) = (P+2)*Exp_msk1;
+ word1(&u) = 0;
+ return u.d;
+ }
+ else {
+ assert(word0(x) || word1(x)); /* x != 0.0 */
+ return ulp(x);
+ }
+}
+
+/* The bigcomp function handles some hard cases for strtod, for inputs
+ with more than STRTOD_DIGLIM digits. It's called once an initial
+ estimate for the double corresponding to the input string has
+ already been obtained by the code in _Py_dg_strtod.
-/* return 0 on success, -1 on failure */
+ The bigcomp function is only called after _Py_dg_strtod has found a
+ double value rv such that either rv or rv + 1ulp represents the
+ correctly rounded value corresponding to the original string. It
+ determines which of these two values is the correct one by
+ computing the decimal digits of rv + 0.5ulp and comparing them with
+ the corresponding digits of s0.
+
+ In the following, write dv for the absolute value of the number represented
+ by the input string.
+
+ Inputs:
+
+ s0 points to the first significant digit of the input string.
+
+ rv is a (possibly scaled) estimate for the closest double value to the
+ value represented by the original input to _Py_dg_strtod. If
+ bc->scale is nonzero, then rv/2^(bc->scale) is the approximation to
+ the input value.
+
+ bc is a struct containing information gathered during the parsing and
+ estimation steps of _Py_dg_strtod. Description of fields follows:
+
+ bc->dsign is 1 if rv < decimal value, 0 if rv >= decimal value. In
+ normal use, it should almost always be 1 when bigcomp is entered.
+
+ bc->e0 gives the exponent of the input value, such that dv = (integer
+ given by the bd->nd digits of s0) * 10**e0
+
+ bc->nd gives the total number of significant digits of s0. It will
+ be at least 1.
+
+ bc->nd0 gives the number of significant digits of s0 before the
+ decimal separator. If there's no decimal separator, bc->nd0 ==
+ bc->nd.
+
+ bc->scale is the value used to scale rv to avoid doing arithmetic with
+ subnormal values. It's either 0 or 2*P (=106).
+
+ Outputs:
+
+ On successful exit, rv/2^(bc->scale) is the closest double to dv.
+
+ Returns 0 on success, -1 on failure (e.g., due to a failed malloc call). */
static int
bigcomp(U *rv, const char *s0, BCinfo *bc)
{
Bigint *b, *d;
- int b2, bbits, d2, dd, dig, dsign, i, j, nd, nd0, p2, p5, speccase;
+ int b2, bbits, d2, dd, i, nd, nd0, odd, p2, p5;
- dsign = bc->dsign;
+ dd = 0; /* silence compiler warning about possibly unused variable */
nd = bc->nd;
nd0 = bc->nd0;
- p5 = nd + bc->e0 - 1;
- speccase = 0;
- if (rv->d == 0.) { /* special case: value near underflow-to-zero */
- /* threshold was rounded to zero */
- b = i2b(1);
+ p5 = nd + bc->e0;
+ if (rv->d == 0.) {
+ /* special case because d2b doesn't handle 0.0 */
+ b = i2b(0);
if (b == NULL)
return -1;
- p2 = Emin - P + 1;
- bbits = 1;
- word0(rv) = (P+2) << Exp_shift;
- i = 0;
- {
- speccase = 1;
- --p2;
- dsign = 0;
- goto have_i;
- }
+ p2 = Emin - P + 1; /* = -1074 for IEEE 754 binary64 */
+ bbits = 0;
}
- else
- {
+ else {
b = d2b(rv, &p2, &bbits);
if (b == NULL)
return -1;
+ p2 -= bc->scale;
}
- p2 -= bc->scale;
- /* floor(log2(rv)) == bbits - 1 + p2 */
- /* Check for denormal case. */
+ /* now rv/2^(bc->scale) = b * 2**p2, and b has bbits significant bits */
+
+ /* Replace (b, p2) by (b << i, p2 - i), with i the largest integer such
+ that b << i has at most P significant bits and p2 - i >= Emin - P +
+ 1. */
i = P - bbits;
- if (i > (j = P - Emin - 1 + p2)) {
- i = j;
- }
- {
- b = lshift(b, ++i);
- if (b == NULL)
- return -1;
- b->x[0] |= 1;
- }
- have_i:
+ if (i > p2 - (Emin - P + 1))
+ i = p2 - (Emin - P + 1);
+ /* increment i so that we shift b by an extra bit; then or-ing a 1 into
+ the lsb of b gives us rv/2^(bc->scale) + 0.5ulp. */
+ b = lshift(b, ++i);
+ if (b == NULL)
+ return -1;
+ /* record whether the lsb of rv/2^(bc->scale) is odd: in the exact halfway
+ case, this is used for round to even. */
+ odd = b->x[0] & 2;
+ b->x[0] |= 1;
+
p2 -= p5 + i;
d = i2b(1);
if (d == NULL) {
@@ -1227,81 +1387,51 @@
}
}
- /* Now b/d = exactly half-way between the two floating-point values */
- /* on either side of the input string. Compute first digit of b/d. */
+ /* if b >= d, round down */
+ if (cmp(b, d) >= 0) {
+ dd = -1;
+ goto ret;
+ }
- if (!(dig = quorem(b,d))) {
- b = multadd(b, 10, 0); /* very unlikely */
+ /* Compare b/d with s0 */
+ for(i = 0; i < nd0; i++) {
+ b = multadd(b, 10, 0);
if (b == NULL) {
Bfree(d);
return -1;
}
- dig = quorem(b,d);
- }
-
- /* Compare b/d with s0 */
-
- assert(nd > 0);
- dd = 9999; /* silence gcc compiler warning */
- for(i = 0; i < nd0; ) {
- if ((dd = s0[i++] - '0' - dig))
+ dd = *s0++ - '0' - quorem(b, d);
+ if (dd)
goto ret;
if (!b->x[0] && b->wds == 1) {
- if (i < nd)
+ if (i < nd - 1)
dd = 1;
goto ret;
}
+ }
+ s0++;
+ for(; i < nd; i++) {
b = multadd(b, 10, 0);
if (b == NULL) {
Bfree(d);
return -1;
}
- dig = quorem(b,d);
- }
- for(j = bc->dp1; i++ < nd;) {
- if ((dd = s0[j++] - '0' - dig))
+ dd = *s0++ - '0' - quorem(b, d);
+ if (dd)
goto ret;
if (!b->x[0] && b->wds == 1) {
- if (i < nd)
+ if (i < nd - 1)
dd = 1;
goto ret;
}
- b = multadd(b, 10, 0);
- if (b == NULL) {
- Bfree(d);
- return -1;
- }
- dig = quorem(b,d);
}
if (b->x[0] || b->wds > 1)
dd = -1;
ret:
Bfree(b);
Bfree(d);
- if (speccase) {
- if (dd <= 0)
- rv->d = 0.;
- }
- else if (dd < 0) {
- if (!dsign) /* does not happen for round-near */
- retlow1:
- dval(rv) -= ulp(rv);
- }
- else if (dd > 0) {
- if (dsign) {
- rethi1:
- dval(rv) += ulp(rv);
- }
- }
- else {
- /* Exact half-way case: apply round-even rule. */
- if (word1(rv) & 1) {
- if (dsign)
- goto rethi1;
- goto retlow1;
- }
- }
-
+ if (dd > 0 || (dd == 0 && odd))
+ dval(rv) += sulp(rv, bc);
return 0;
}
@@ -1312,13 +1442,13 @@
int esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
const char *s, *s0, *s1;
double aadj, aadj1;
- Long L;
U aadj2, adj, rv, rv0;
- ULong y, z;
+ ULong y, z, abse;
+ Long L;
BCinfo bc;
Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
- sign = nz0 = nz = bc.dplen = bc.uflchk = 0;
+ sign = nz0 = nz = 0;
dval(&rv) = 0.;
for(s = s00;;s++) switch(*s) {
case '-':
@@ -1350,18 +1480,11 @@
goto ret;
}
s0 = s;
- y = z = 0;
for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
- if (nd < 9)
- y = 10*y + c - '0';
- else if (nd < 16)
- z = 10*z + c - '0';
+ ;
nd0 = nd;
- bc.dp0 = bc.dp1 = s - s0;
if (c == '.') {
c = *++s;
- bc.dp1 = s - s0;
- bc.dplen = bc.dp1 - bc.dp0;
if (!nd) {
for(; c == '0'; c = *++s)
nz++;
@@ -1378,15 +1501,7 @@
nz++;
if (c -= '0') {
nf += nz;
- for(i = 1; i < nz; i++)
- if (nd++ < 9)
- y *= 10;
- else if (nd <= DBL_DIG + 1)
- z *= 10;
- if (nd++ < 9)
- y = 10*y + c;
- else if (nd <= DBL_DIG + 1)
- z = 10*z + c;
+ nd += nz;
nz = 0;
}
}
@@ -1409,17 +1524,17 @@
while(c == '0')
c = *++s;
if (c > '0' && c <= '9') {
- L = c - '0';
+ abse = c - '0';
s1 = s;
while((c = *++s) >= '0' && c <= '9')
- L = 10*L + c - '0';
- if (s - s1 > 8 || L > 19999)
+ abse = 10*abse + c - '0';
+ if (s - s1 > 8 || abse > MAX_ABS_EXP)
/* Avoid confusion from exponents
* so large that e might overflow.
*/
- e = 19999; /* safe for 16 bit ints */
+ e = (int)MAX_ABS_EXP; /* safe for 16 bit ints */
else
- e = (int)L;
+ e = (int)abse;
if (esign)
e = -e;
}
@@ -1437,15 +1552,78 @@
}
goto ret;
}
- bc.e0 = e1 = e -= nf;
+ e -= nf;
+ if (!nd0)
+ nd0 = nd;
+
+ /* strip trailing zeros */
+ for (i = nd; i > 0; ) {
+ /* scan back until we hit a nonzero digit. significant digit 'i'
+ is s0[i] if i < nd0, s0[i+1] if i >= nd0. */
+ --i;
+ if (s0[i < nd0 ? i : i+1] != '0') {
+ ++i;
+ break;
+ }
+ }
+ e += nd - i;
+ nd = i;
+ if (nd0 > nd)
+ nd0 = nd;
/* Now we have nd0 digits, starting at s0, followed by a
* decimal point, followed by nd-nd0 digits. The number we're
* after is the integer represented by those digits times
* 10**e */
- if (!nd0)
- nd0 = nd;
+ bc.e0 = e1 = e;
+
+ /* Summary of parsing results. The parsing stage gives values
+ * s0, nd0, nd, e, sign, where:
+ *
+ * - s0 points to the first significant digit of the input string s00;
+ *
+ * - nd is the total number of significant digits (here, and
+ * below, 'significant digits' means the set of digits of the
+ * significand of the input that remain after ignoring leading
+ * and trailing zeros.
+ *
+ * - nd0 indicates the position of the decimal point (if
+ * present): so the nd significant digits are in s0[0:nd0] and
+ * s0[nd0+1:nd+1] using the usual Python half-open slice
+ * notation. (If nd0 < nd, then s0[nd0] necessarily contains
+ * a '.' character; if nd0 == nd, then it could be anything.)
+ *
+ * - e is the adjusted exponent: the absolute value of the number
+ * represented by the original input string is n * 10**e, where
+ * n is the integer represented by the concatenation of
+ * s0[0:nd0] and s0[nd0+1:nd+1]
+ *
+ * - sign gives the sign of the input: 1 for negative, 0 for positive
+ *
+ * - the first and last significant digits are nonzero
+ */
+
+ /* put first DBL_DIG+1 digits into integer y and z.
+ *
+ * - y contains the value represented by the first min(9, nd)
+ * significant digits
+ *
+ * - if nd > 9, z contains the value represented by significant digits
+ * with indices in [9, min(16, nd)). So y * 10**(min(16, nd) - 9) + z
+ * gives the value represented by the first min(16, nd) sig. digits.
+ */
+
+ y = z = 0;
+ for (i = 0; i < nd; i++) {
+ if (i < 9)
+ y = 10*y + s0[i < nd0 ? i : i+1] - '0';
+ else if (i < DBL_DIG+1)
+ z = 10*z + s0[i < nd0 ? i : i+1] - '0';
+ else
+ break;
+ }
+
k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
dval(&rv) = y;
if (k > 9) {
@@ -1555,22 +1733,25 @@
/* Put digits into bd: true value = bd * 10^e */
bc.nd = nd;
- bc.nd0 = nd0; /* Only needed if nd > strtod_diglim, but done here */
+ bc.nd0 = nd0; /* Only needed if nd > STRTOD_DIGLIM, but done here */
/* to silence an erroneous warning about bc.nd0 */
/* possibly not being initialized. */
- if (nd > strtod_diglim) {
- /* ASSERT(strtod_diglim >= 18); 18 == one more than the */
+ if (nd > STRTOD_DIGLIM) {
+ /* ASSERT(STRTOD_DIGLIM >= 18); 18 == one more than the */
/* minimum number of decimal digits to distinguish double values */
/* in IEEE arithmetic. */
- i = j = 18;
- if (i > nd0)
- j += bc.dplen;
- for(;;) {
- if (--j <= bc.dp1 && j >= bc.dp0)
- j = bc.dp0 - 1;
- if (s0[j] != '0')
- break;
+
+ /* Truncate input to 18 significant digits, then discard any trailing
+ zeros on the result by updating nd, nd0, e and y suitably. (There's
+ no need to update z; it's not reused beyond this point.) */
+ for (i = 18; i > 0; ) {
+ /* scan back until we hit a nonzero digit. significant digit 'i'
+ is s0[i] if i < nd0, s0[i+1] if i >= nd0. */
--i;
+ if (s0[i < nd0 ? i : i+1] != '0') {
+ ++i;
+ break;
+ }
}
e += nd - i;
nd = i;
@@ -1580,11 +1761,11 @@
y = 0;
for(i = 0; i < nd0; ++i)
y = 10*y + s0[i] - '0';
- for(j = bc.dp1; i < nd; ++i)
- y = 10*y + s0[j++] - '0';
+ for(; i < nd; ++i)
+ y = 10*y + s0[i+1] - '0';
}
}
- bd0 = s2b(s0, nd0, nd, y, bc.dplen);
+ bd0 = s2b(s0, nd0, nd, y);
if (bd0 == NULL)
goto failed_malloc;
@@ -1707,6 +1888,30 @@
if (bc.nd > nd && i <= 0) {
if (bc.dsign)
break; /* Must use bigcomp(). */
+
+ /* Here rv overestimates the truncated decimal value by at most
+ 0.5 ulp(rv). Hence rv either overestimates the true decimal
+ value by <= 0.5 ulp(rv), or underestimates it by some small
+ amount (< 0.1 ulp(rv)); either way, rv is within 0.5 ulps of
+ the true decimal value, so it's possible to exit.
+
+ Exception: if scaled rv is a normal exact power of 2, but not
+ DBL_MIN, then rv - 0.5 ulp(rv) takes us all the way down to the
+ next double, so the correctly rounded result is either rv - 0.5
+ ulp(rv) or rv; in this case, use bigcomp to distinguish. */
+
+ if (!word1(&rv) && !(word0(&rv) & Bndry_mask)) {
+ /* rv can't be 0, since it's an overestimate for some
+ nonzero value. So rv is a normal power of 2. */
+ j = (int)(word0(&rv) & Exp_mask) >> Exp_shift;
+ /* rv / 2^bc.scale = 2^(j - 1023 - bc.scale); use bigcomp if
+ rv / 2^bc.scale >= 2^-1021. */
+ if (j - bc.scale >= 2) {
+ dval(&rv) -= 0.5 * sulp(&rv, &bc);
+ break;
+ }
+ }
+
{
bc.nd = nd;
i = -1; /* Discarded digits make delta smaller. */
@@ -1767,10 +1972,8 @@
/* accept rv */
break;
/* rv = smallest denormal */
- if (bc.nd >nd) {
- bc.uflchk = 1;
+ if (bc.nd >nd)
break;
- }
goto undfl;
}
}
@@ -1786,10 +1989,8 @@
else {
dval(&rv) -= ulp(&rv);
if (!dval(&rv)) {
- if (bc.nd >nd) {
- bc.uflchk = 1;
+ if (bc.nd >nd)
break;
- }
goto undfl;
}
}
@@ -1801,10 +2002,8 @@
aadj = aadj1 = 1.;
else if (word1(&rv) || word0(&rv) & Bndry_mask) {
if (word1(&rv) == Tiny1 && !word0(&rv)) {
- if (bc.nd >nd) {
- bc.uflchk = 1;
+ if (bc.nd >nd)
break;
- }
goto undfl;
}
aadj = 1.;
@@ -1838,8 +2037,14 @@
dval(&rv) += adj.d;
if ((word0(&rv) & Exp_mask) >=
Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
- if (word0(&rv0) == Big0 && word1(&rv0) == Big1)
+ if (word0(&rv0) == Big0 && word1(&rv0) == Big1) {
+ Bfree(bb);
+ Bfree(bd);
+ Bfree(bs);
+ Bfree(bd0);
+ Bfree(delta);
goto ovfl;
+ }
word0(&rv) = Big0;
word1(&rv) = Big1;
goto cont;
Modified: python/branches/py3k-cdecimal/Python/peephole.c
==============================================================================
--- python/branches/py3k-cdecimal/Python/peephole.c (original)
+++ python/branches/py3k-cdecimal/Python/peephole.c Thu Jan 21 20:32:23 2010
@@ -31,7 +31,8 @@
new constant (c1, c2, ... cn) can be appended.
Called with codestr pointing to the first LOAD_CONST.
Bails out with no change if one or more of the LOAD_CONSTs is missing.
- Also works for BUILD_LIST when followed by an "in" or "not in" test.
+ Also works for BUILD_LIST and BUILT_SET when followed by an "in" or "not in"
+ test; for BUILD_SET it assembles a frozenset rather than a tuple.
*/
static int
tuple_of_constants(unsigned char *codestr, Py_ssize_t n, PyObject *consts)
@@ -41,7 +42,7 @@
/* Pre-conditions */
assert(PyList_CheckExact(consts));
- assert(codestr[n*3] == BUILD_TUPLE || codestr[n*3] == BUILD_LIST);
+ assert(codestr[n*3] == BUILD_TUPLE || codestr[n*3] == BUILD_LIST || codestr[n*3] == BUILD_SET);
assert(GETARG(codestr, (n*3)) == n);
for (i=0 ; i<n ; i++)
assert(codestr[i*3] == LOAD_CONST);
@@ -59,6 +60,16 @@
PyTuple_SET_ITEM(newconst, i, constant);
}
+ /* If it's a BUILD_SET, use the PyTuple we just built to create a
+ PyFrozenSet, and use that as the constant instead: */
+ if (codestr[n*3] == BUILD_SET) {
+ PyObject *tuple = newconst;
+ newconst = PyFrozenSet_New(tuple);
+ Py_DECREF(tuple);
+ if (newconst == NULL)
+ return 0;
+ }
+
/* Append folded constant onto consts */
if (PyList_Append(consts, newconst)) {
Py_DECREF(newconst);
@@ -436,20 +447,21 @@
cumlc = 0;
break;
- /* Try to fold tuples of constants (includes a case for lists
+ /* Try to fold tuples of constants (includes a case for lists and sets
which are only used for "in" and "not in" tests).
Skip over BUILD_SEQN 1 UNPACK_SEQN 1.
Replace BUILD_SEQN 2 UNPACK_SEQN 2 with ROT2.
Replace BUILD_SEQN 3 UNPACK_SEQN 3 with ROT3 ROT2. */
case BUILD_TUPLE:
case BUILD_LIST:
+ case BUILD_SET:
j = GETARG(codestr, i);
h = i - 3 * j;
if (h >= 0 &&
j <= lastlc &&
((opcode == BUILD_TUPLE &&
ISBASICBLOCK(blocks, h, 3*(j+1))) ||
- (opcode == BUILD_LIST &&
+ ((opcode == BUILD_LIST || opcode == BUILD_SET) &&
codestr[i+3]==COMPARE_OP &&
ISBASICBLOCK(blocks, h, 3*(j+2)) &&
(GETARG(codestr,i+3)==6 ||
Modified: python/branches/py3k-cdecimal/setup.py
==============================================================================
--- python/branches/py3k-cdecimal/setup.py (original)
+++ python/branches/py3k-cdecimal/setup.py Thu Jan 21 20:32:23 2010
@@ -1108,12 +1108,12 @@
# Interface to the Expat XML parser
#
- # Expat was written by James Clark and is now maintained by a
- # group of developers on SourceForge; see www.libexpat.org for
- # more information. The pyexpat module was written by Paul
- # Prescod after a prototype by Jack Jansen. The Expat source
- # is included in Modules/expat/. Usage of a system
- # shared libexpat.so/expat.dll is not advised.
+ # Expat was written by James Clark and is now maintained by a group of
+ # developers on SourceForge; see www.libexpat.org for more information.
+ # The pyexpat module was written by Paul Prescod after a prototype by
+ # Jack Jansen. The Expat source is included in Modules/expat/. Usage
+ # of a system shared libexpat.so is possible with --with-system-expat
+ # cofigure option.
#
# More information on Expat can be found at www.libexpat.org.
#
@@ -1501,22 +1501,19 @@
return False
fficonfig = {}
- fp = open(ffi_configfile)
- try:
- script = fp.read()
- finally:
- fp.close()
- exec(script, globals(), fficonfig)
- ffi_srcdir = os.path.join(fficonfig['ffi_srcdir'], 'src')
+ with open(ffi_configfile) as f:
+ exec(f.read(), globals(), fficonfig)
# Add .S (preprocessed assembly) to C compiler source extensions.
self.compiler_obj.src_extensions.append('.S')
include_dirs = [os.path.join(ffi_builddir, 'include'),
- ffi_builddir, ffi_srcdir]
+ ffi_builddir,
+ os.path.join(ffi_srcdir, 'src')]
extra_compile_args = fficonfig['ffi_cflags'].split()
- ext.sources.extend(fficonfig['ffi_sources'])
+ ext.sources.extend(os.path.join(ffi_srcdir, f) for f in
+ fficonfig['ffi_sources'])
ext.include_dirs.extend(include_dirs)
ext.extra_compile_args.extend(extra_compile_args)
return True
More information about the Python-checkins
mailing list