From 86b2fb9d77e483cc56e85bc4c96ac54f55427d39 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 16 Jul 2008 03:43:04 +0000 Subject: [PATCH] Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r64623 | benjamin.peterson | 2008-07-01 21:51:54 +0200 (Tue, 01 Jul 2008) | 1 line write a short little section for multiprocessing; it still needs help ........ r64640 | georg.brandl | 2008-07-01 22:56:03 +0200 (Tue, 01 Jul 2008) | 2 lines Add a comment about incref'ing w. ........ r64665 | jesse.noller | 2008-07-02 18:56:51 +0200 (Wed, 02 Jul 2008) | 1 line Add #!/usr/bin/env python for ben ........ r64687 | andrew.kuchling | 2008-07-03 14:50:03 +0200 (Thu, 03 Jul 2008) | 1 line Tweak wording ........ r64689 | benjamin.peterson | 2008-07-03 14:57:35 +0200 (Thu, 03 Jul 2008) | 1 line lowercase glossary term ........ r64690 | benjamin.peterson | 2008-07-03 15:01:17 +0200 (Thu, 03 Jul 2008) | 1 line let the term be linked ........ r64719 | raymond.hettinger | 2008-07-05 04:11:55 +0200 (Sat, 05 Jul 2008) | 1 line Update comment on prediction macros. ........ r64721 | georg.brandl | 2008-07-05 12:07:18 +0200 (Sat, 05 Jul 2008) | 2 lines Fix tabs. ........ r64735 | mark.dickinson | 2008-07-05 17:25:48 +0200 (Sat, 05 Jul 2008) | 3 lines Minor rewrite of cmath_log to work around a Sun compiler bug. See issue #3168. ........ r64742 | benjamin.peterson | 2008-07-05 18:29:38 +0200 (Sat, 05 Jul 2008) | 1 line make regrtest aware of the lib2to3 resource ........ r64744 | georg.brandl | 2008-07-05 18:43:45 +0200 (Sat, 05 Jul 2008) | 2 lines Keep below 80 chars. ........ r64745 | facundo.batista | 2008-07-05 21:19:50 +0200 (Sat, 05 Jul 2008) | 3 lines Issue 3289. Removed two lines that ended doing nothing. ........ r64746 | facundo.batista | 2008-07-05 22:39:59 +0200 (Sat, 05 Jul 2008) | 4 lines Issue #3239. Differentiate the ascii call from the curses one and the builtin one. ........ r64756 | gregory.p.smith | 2008-07-06 09:16:40 +0200 (Sun, 06 Jul 2008) | 3 lines - Issue #2113: Fix error in subprocess.Popen if the select system call is interrupted by a signal. ........ r64757 | benjamin.peterson | 2008-07-06 14:39:09 +0200 (Sun, 06 Jul 2008) | 1 line remove test_compact_freelists from test_sys ........ r64758 | gregory.p.smith | 2008-07-06 19:06:29 +0200 (Sun, 06 Jul 2008) | 2 lines fix issue3304 - remove an incorrect PyMem_Free in fileio_init ........ r64759 | georg.brandl | 2008-07-06 19:36:20 +0200 (Sun, 06 Jul 2008) | 2 lines Fix opensearch template. ........ r64760 | andrew.kuchling | 2008-07-06 19:43:16 +0200 (Sun, 06 Jul 2008) | 1 line Wording fix ........ r64761 | andrew.kuchling | 2008-07-06 19:44:17 +0200 (Sun, 06 Jul 2008) | 1 line Add two items; rewrap paragraph ........ r64767 | gregory.p.smith | 2008-07-07 06:31:58 +0200 (Mon, 07 Jul 2008) | 4 lines - Issue #3309: Fix bz2.BZFile itererator to release its internal lock properly when raising an exception due to the bz2file being closed. Prevents a deadlock. ........ r64768 | josiah.carlson | 2008-07-07 06:51:46 +0200 (Mon, 07 Jul 2008) | 2 lines Fixed bugs 760475, 953599, and 1519. ........ r64769 | gregory.p.smith | 2008-07-07 06:54:31 +0200 (Mon, 07 Jul 2008) | 2 lines Add commented out #_sha256 and #_sha512 lines per issue 3183. ........ r64771 | gregory.p.smith | 2008-07-07 07:09:12 +0200 (Mon, 07 Jul 2008) | 4 lines - Issue #3094: httplib.HTTPSConnection Host: headers no longer include the redundant ":443" port number designation when the connection is using the default https port (443). ........ r64772 | skip.montanaro | 2008-07-07 13:16:14 +0200 (Mon, 07 Jul 2008) | 2 lines Correct grammar. ........ r64774 | andrew.kuchling | 2008-07-07 18:51:09 +0200 (Mon, 07 Jul 2008) | 1 line Fix example to match text ........ r64775 | facundo.batista | 2008-07-07 19:02:59 +0200 (Mon, 07 Jul 2008) | 3 lines Issue 3306. Better control for a lenght in findmax() function. ........ r64788 | georg.brandl | 2008-07-08 09:05:23 +0200 (Tue, 08 Jul 2008) | 2 lines Add missing ABCs to list. ........ r64793 | nick.coghlan | 2008-07-08 16:21:42 +0200 (Tue, 08 Jul 2008) | 1 line Add missing NEWS and ACK entries for r64791 ........ r64835 | raymond.hettinger | 2008-07-10 11:31:08 +0200 (Thu, 10 Jul 2008) | 1 line Issue 3287: Raise correct exception for float inputs. ........ r64836 | raymond.hettinger | 2008-07-10 12:28:41 +0200 (Thu, 10 Jul 2008) | 1 line Use operator.index() instead of n.__index__(). ........ --- Doc/glossary.rst | 2 +- Doc/library/abc.rst | 4 +- Doc/library/collections.rst | 80 ++++++++++++++++-------------- Doc/library/shutil.rst | 39 +++++++++++---- Doc/library/stdtypes.rst | 2 +- Doc/tools/sphinxext/opensearch.xml | 18 ++----- Doc/whatsnew/2.6.rst | 30 +++++++++-- Lib/curses/textpad.py | 37 +++++++------- Lib/fractions.py | 5 +- Lib/http/client.py | 2 +- Lib/subprocess.py | 7 ++- Lib/test/regrtest.py | 6 ++- Lib/test/test_audioop.py | 4 ++ Lib/test/test_bz2.py | 11 ++++ Lib/test/test_fractions.py | 8 +-- Lib/test/test_multiprocessing.py | 2 + Lib/test/test_sys.py | 15 ------ Misc/ACKS | 1 + Modules/Setup.dist | 6 ++- Modules/_fileio.c | 1 - Modules/audioop.c | 2 +- Modules/bz2module.c | 1 + Modules/cmathmodule.c | 6 ++- Modules/timemodule.c | 2 - Objects/abstract.c | 2 +- Python/ceval.c | 22 ++++---- Python/pythonrun.c | 24 ++++----- 27 files changed, 198 insertions(+), 141 deletions(-) diff --git a/Doc/glossary.rst b/Doc/glossary.rst index f7a4b569b39..a2e9b0213e1 100644 --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -16,7 +16,7 @@ Glossary The typical Python prompt of the interactive shell when entering code for an indented code block. - Abstract Base Class + abstract base class Abstract Base Classes (abbreviated ABCs) complement :term:`duck-typing` by providing a way to define interfaces when other techniques like :func:`hasattr` would be clumsy. Python comes with many builtin ABCs for data structures diff --git a/Doc/library/abc.rst b/Doc/library/abc.rst index 21d3018a737..b03fc83a70e 100644 --- a/Doc/library/abc.rst +++ b/Doc/library/abc.rst @@ -8,8 +8,8 @@ .. sectionauthor:: Georg Brandl .. much of the content adapted from docstrings -This module provides the infrastructure for defining :term:`abstract base -classes` (ABCs) in Python, as outlined in :pep:`3119`; see the PEP for why this +This module provides the infrastructure for defining an :term:`abstract base +class` (ABCs) in Python, as outlined in :pep:`3119`; see the PEP for why this was added to Python. (See also :pep:`3141` and the :mod:`numbers` module regarding a type hierarchy for numbers based on ABCs.) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 7718c5121d0..d2d4f4750fc 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -37,42 +37,50 @@ ABCs - abstract base classes The collections module offers the following ABCs: -========================= ==================== ====================== ==================================================== -ABC Inherits Abstract Methods Mixin Methods -========================= ==================== ====================== ==================================================== -:class:`Container` ``__contains__`` -:class:`Hashable` ``__hash__`` -:class:`Iterable` ``__iter__`` -:class:`Iterator` :class:`Iterable` ``__next__`` ``__iter__`` -:class:`Sized` ``__len__`` - -:class:`Mapping` :class:`Sized`, ``__getitem__``, ``__contains__``, ``keys``, ``items``, ``values``, - :class:`Iterable`, ``__len__``. and ``get``, ``__eq__``, and ``__ne__`` - :class:`Container` ``__iter__`` - -:class:`MutableMapping` :class:`Mapping` ``__getitem__`` Inherited Mapping methods and - ``__setitem__``, ``pop``, ``popitem``, ``clear``, ``update``, - ``__delitem__``, and ``setdefault`` - ``__iter__``, and - ``__len__`` - -:class:`Sequence` :class:`Sized`, ``__getitem__`` ``__contains__``. ``__iter__``, ``__reversed__``. - :class:`Iterable`, and ``__len__`` ``index``, and ``count`` - :class:`Container` - -:class:`MutableSequnce` :class:`Sequence` ``__getitem__`` Inherited Sequence methods and - ``__delitem__``, ``append``, ``reverse``, ``extend``, ``pop``, - ``insert``, ``remove``, and ``__iadd__`` - and ``__len__`` - -:class:`Set` :class:`Sized`, ``__len__``, ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``, - :class:`Iterable`, ``__iter__``, and ``__gt__``, ``__ge__``, ``__and__``, ``__or__`` - :class:`Container` ``__contains__`` ``__sub__``, ``__xor__``, and ``isdisjoint`` - -:class:`MutableSet` :class:`Set` ``add`` and Inherited Set methods and - ``discard`` ``clear``, ``pop``, ``remove``, ``__ior__``, - ``__iand__``, ``__ixor__``, and ``__isub__`` -========================= ==================== ====================== ==================================================== +========================= ===================== ====================== ==================================================== +ABC Inherits Abstract Methods Mixin Methods +========================= ===================== ====================== ==================================================== +:class:`Container` ``__contains__`` +:class:`Hashable` ``__hash__`` +:class:`Iterable` ``__iter__`` +:class:`Iterator` :class:`Iterable` ``__next__`` ``__iter__`` +:class:`Sized` ``__len__`` +:class:`Callable` ``__call__`` + +:class:`Sequence` :class:`Sized`, ``__getitem__`` ``__contains__``. ``__iter__``, ``__reversed__``. + :class:`Iterable`, and ``__len__`` ``index``, and ``count`` + :class:`Container` + +:class:`MutableSequnce` :class:`Sequence` ``__getitem__`` Inherited Sequence methods and + ``__delitem__``, ``append``, ``reverse``, ``extend``, ``pop``, + ``insert``, ``remove``, and ``__iadd__`` + and ``__len__`` + +:class:`Set` :class:`Sized`, ``__len__``, ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``, + :class:`Iterable`, ``__iter__``, and ``__gt__``, ``__ge__``, ``__and__``, ``__or__`` + :class:`Container` ``__contains__`` ``__sub__``, ``__xor__``, and ``isdisjoint`` + +:class:`MutableSet` :class:`Set` ``add`` and Inherited Set methods and + ``discard`` ``clear``, ``pop``, ``remove``, ``__ior__``, + ``__iand__``, ``__ixor__``, and ``__isub__`` + +:class:`Mapping` :class:`Sized`, ``__getitem__``, ``__contains__``, ``keys``, ``items``, ``values``, + :class:`Iterable`, ``__len__``. and ``get``, ``__eq__``, and ``__ne__`` + :class:`Container` ``__iter__`` + +:class:`MutableMapping` :class:`Mapping` ``__getitem__`` Inherited Mapping methods and + ``__setitem__``, ``pop``, ``popitem``, ``clear``, ``update``, + ``__delitem__``, and ``setdefault`` + ``__iter__``, and + ``__len__`` + +:class:`MappingView` :class:`Sized` ``__len__`` +:class:`KeysView` :class:`MappingView`, ``__contains__``, + :class:`Set` ``__iter__`` +:class:`ItemsView` :class:`MappingView`, ``__contains__``, + :class:`Set` ``__iter__`` +:class:`ValuesView` :class:`MappingView` ``__contains__``, ``__iter__`` +========================= ===================== ====================== ==================================================== These ABCs allow us to ask classes or instances if they provide particular functionality, for example:: diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst index 5ab2f29ef16..c295f290f5e 100644 --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -78,18 +78,39 @@ copying and removal. For operations on individual files, see also the Unix command :program:`cp -p`. -.. function:: copytree(src, dst[, symlinks]) +.. function:: ignore_patterns(\*patterns) + + This factory function creates a function that can be used as a callable for + :func:`copytree`\'s *ignore* argument, ignoring files and directories that + match one of the glob-style *patterns* provided. See the example below. + + +.. function:: copytree(src, dst[, symlinks=False[, ignore=None]]) Recursively copy an entire directory tree rooted at *src*. The destination - directory, named by *dst*, must not already exist; it will be created as well as - missing parent directories. Permissions and times of directories are copied with - :func:`copystat`, individual files are copied using :func:`copy2`. If - *symlinks* is true, symbolic links in the source tree are represented as - symbolic links in the new tree; if false or omitted, the contents of the linked - files are copied to the new tree. If exception(s) occur, an :exc:`Error` is - raised with a list of reasons. + directory, named by *dst*, must not already exist; it will be created as well + as missing parent directories. Permissions and times of directories are + copied with :func:`copystat`, individual files are copied using + :func:`copy2`. - The source code for this should be considered an example rather than a tool. + If *symlinks* is true, symbolic links in the source tree are represented as + symbolic links in the new tree; if false or omitted, the contents of the + linked files are copied to the new tree. + + If *ignore* is given, it must be a callable that will receive as its + arguments the directory being visited by :func:`copytree`, and a list of its + contents, as returned by :func:`os.listdir`. Since :func:`copytree` is + called recursively, the *ignore* callable will be called once for each + directory that is copied. The callable must return a sequence of directory + and file names relative to the current directory (i.e. a subset of the items + in its second argument); these names will then be ignored in the copy + process. :func:`ignore_patterns` can be used to create such a callable that + ignores names based on glob-style patterns. + + If exception(s) occur, an :exc:`Error` is raised with a list of reasons. + + The source code for this should be considered an example rather than the + ultimate tool. .. function:: rmtree(path[, ignore_errors[, onerror]]) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 9107d0359d0..a97a5195fa8 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2027,7 +2027,7 @@ Files have the following methods: files, like ttys, it makes sense to continue reading after an EOF is hit.) Note that this method may call the underlying C function :cfunc:`fread` more than once in an effort to acquire as close to *size* bytes as possible. Also note - that when in non-blocking mode, less data than what was requested may be + that when in non-blocking mode, less data than was requested may be returned, even if no *size* parameter was given. diff --git a/Doc/tools/sphinxext/opensearch.xml b/Doc/tools/sphinxext/opensearch.xml index d672c2e2b8c..69cec804cd0 100644 --- a/Doc/tools/sphinxext/opensearch.xml +++ b/Doc/tools/sphinxext/opensearch.xml @@ -1,14 +1,4 @@ - - - Python Docs - Python Documentation - Search the Python documentation - utf-8 - - - - - - http://www.python.org/images/favicon16x16.ico - - +{% extends "!opensearch.xml" %} +{% block extra -%} +http://www.python.org/images/favicon16x16.ico +{%- endblock %} diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst index 21ccf9b891d..df5ccb68b20 100644 --- a/Doc/whatsnew/2.6.rst +++ b/Doc/whatsnew/2.6.rst @@ -1681,6 +1681,11 @@ details. available, instead of restricting itself to protocol 1. (Contributed by W. Barnes; :issue:`1551443`.) +* The :mod:`cgi` module will now read variables from the query string of an + HTTP POST request. This makes it possible to use form actions with + URLs such as "/cgi-bin/add.py?category=1". (Contributed by + Alexandre Fiori and Nubis; :issue:`1817`.) + * The :mod:`cmath` module underwent an extensive set of revisions, thanks to Mark Dickinson and Christian Heimes, that added some new features and greatly improved the accuracy of the computations. @@ -2137,6 +2142,24 @@ details. * The :mod:`sets` module has been deprecated; it's better to use the built-in :class:`set` and :class:`frozenset` types. +* The :func:`shutil.copytree` function now has an optional **ignore** argument + that takes a callable object. This callable will receive each directory path + and a list of the directory's contents, and returns a list of names that + will be ignored, not copied. + + The :mod:`shutil` module also provides an :func:`ignore_patterns` + function for use with this new parameter. + :func:`ignore_patterns` takes an arbitrary number of glob-style patterns + and will ignore any files and directories that match this pattern. + The following example copies a directory tree, but skip both SVN's internal + :file:`.svn` directories and Emacs backup + files, which have names ending with '~':: + + shutil.copytree('Doc/library', '/tmp/library', + ignore=shutil.ignore_patterns('*~', '.svn')) + + (Contributed by Tarek Ziadé; :issue:`2663`.) + * Integrating signal handling with GUI handling event loops like those used by Tkinter or GTk+ has long been a problem; most software ends up polling, waking up every fraction of a second. @@ -2500,9 +2523,10 @@ handle it safely:: ... ValueError: malformed string -The module also includes -:class:`NodeVisitor` and :class:`NodeTransformer` classes -for traversing and modifying an AST, and functions for common transformations such as changing line numbers. +The module also includes :class:`NodeVisitor` and +:class:`NodeTransformer` classes for traversing and modifying an AST, +and functions for common transformations such as changing line +numbers. .. ====================================================================== diff --git a/Lib/curses/textpad.py b/Lib/curses/textpad.py index a05b82bdb6e..2b4b4cb669f 100644 --- a/Lib/curses/textpad.py +++ b/Lib/curses/textpad.py @@ -1,6 +1,7 @@ """Simple textbox editing widget with Emacs-like keybindings.""" -import curses, ascii +import curses +import curses.ascii def rectangle(win, uly, ulx, lry, lrx): """Draw a rectangle with corners at the provided upper-left @@ -54,7 +55,7 @@ def _end_of_line(self, y): returning the index of the last non-blank character.""" last = self.maxx while True: - if ascii.ascii(self.win.inch(y, last)) != ascii.SP: + if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP: last = min(self.maxx, last+1) break elif last == 0: @@ -76,7 +77,7 @@ def _insert_printable_char(self, ch): pass if self.insert_mode: (backy, backx) = self.win.getyx() - if ascii.isprint(oldch): + if curses.ascii.isprint(oldch): self._insert_printable_char(oldch) self.win.move(backy, backx) @@ -84,12 +85,12 @@ def do_command(self, ch): "Process a single editing command." (y, x) = self.win.getyx() self.lastcmd = ch - if ascii.isprint(ch): + if curses.ascii.isprint(ch): if y < self.maxy or x < self.maxx: self._insert_printable_char(ch) - elif ch == ascii.SOH: # ^a + elif ch == curses.ascii.SOH: # ^a self.win.move(y, 0) - elif ch in (ascii.STX,curses.KEY_LEFT, ascii.BS,curses.KEY_BACKSPACE): + elif ch in (curses.ascii.STX,curses.KEY_LEFT, curses.ascii.BS,curses.KEY_BACKSPACE): if x > 0: self.win.move(y, x-1) elif y == 0: @@ -98,46 +99,46 @@ def do_command(self, ch): self.win.move(y-1, self._end_of_line(y-1)) else: self.win.move(y-1, self.maxx) - if ch in (ascii.BS, curses.KEY_BACKSPACE): + if ch in (curses.ascii.BS, curses.KEY_BACKSPACE): self.win.delch() - elif ch == ascii.EOT: # ^d + elif ch == curses.ascii.EOT: # ^d self.win.delch() - elif ch == ascii.ENQ: # ^e + elif ch == curses.ascii.ENQ: # ^e if self.stripspaces: self.win.move(y, self._end_of_line(y)) else: self.win.move(y, self.maxx) - elif ch in (ascii.ACK, curses.KEY_RIGHT): # ^f + elif ch in (curses.ascii.ACK, curses.KEY_RIGHT): # ^f if x < self.maxx: self.win.move(y, x+1) elif y == self.maxy: pass else: self.win.move(y+1, 0) - elif ch == ascii.BEL: # ^g + elif ch == curses.ascii.BEL: # ^g return 0 - elif ch == ascii.NL: # ^j + elif ch == curses.ascii.NL: # ^j if self.maxy == 0: return 0 elif y < self.maxy: self.win.move(y+1, 0) - elif ch == ascii.VT: # ^k + elif ch == curses.ascii.VT: # ^k if x == 0 and self._end_of_line(y) == 0: self.win.deleteln() else: # first undo the effect of self._end_of_line self.win.move(y, x) self.win.clrtoeol() - elif ch == ascii.FF: # ^l + elif ch == curses.ascii.FF: # ^l self.win.refresh() - elif ch in (ascii.SO, curses.KEY_DOWN): # ^n + elif ch in (curses.ascii.SO, curses.KEY_DOWN): # ^n if y < self.maxy: self.win.move(y+1, x) if x > self._end_of_line(y+1): self.win.move(y+1, self._end_of_line(y+1)) - elif ch == ascii.SI: # ^o + elif ch == curses.ascii.SI: # ^o self.win.insertln() - elif ch in (ascii.DLE, curses.KEY_UP): # ^p + elif ch in (curses.ascii.DLE, curses.KEY_UP): # ^p if y > 0: self.win.move(y-1, x) if x > self._end_of_line(y-1): @@ -155,7 +156,7 @@ def gather(self): for x in range(self.maxx+1): if self.stripspaces and x > stop: break - result = result + chr(ascii.ascii(self.win.inch(y, x))) + result = result + chr(curses.ascii.ascii(self.win.inch(y, x))) if self.maxy > 0: result = result + "\n" return result diff --git a/Lib/fractions.py b/Lib/fractions.py index 329a16fa847..3df628adc0b 100755 --- a/Lib/fractions.py +++ b/Lib/fractions.py @@ -94,9 +94,8 @@ def __new__(cls, numerator=0, denominator=1): if denominator == 0: raise ZeroDivisionError('Fraction(%s, 0)' % numerator) - - numerator = numerator.__index__() - denominator = denominator.__index__() + numerator = operator.index(numerator) + denominator = operator.index(denominator) g = gcd(numerator, denominator) self._numerator = numerator // g self._denominator = denominator // g diff --git a/Lib/http/client.py b/Lib/http/client.py index 96bcd72a932..4a078d38883 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -783,7 +783,7 @@ def putrequest(self, method, url, skip_host=0, skip_accept_encoding=0): host_enc = self.host.encode("ascii") except UnicodeEncodeError: host_enc = self.host.encode("idna") - if self.port == HTTP_PORT: + if self.port == self.default_port: self.putheader('Host', host_enc) else: host_enc = host_enc.decode("ascii") diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 8df10344cbc..e94fc2c6fff 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1149,7 +1149,12 @@ def _communicate(self, input): input_offset = 0 while read_set or write_set: - rlist, wlist, xlist = select.select(read_set, write_set, []) + try: + rlist, wlist, xlist = select.select(read_set, write_set, []) + except select.error as e: + if e.args[0] == errno.EINTR: + continue + raise # XXX Rewrite these to use non-blocking I/O on the # file objects; they are no longer using C stdio! diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index d523d5b4e04..d47fde38e83 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -101,6 +101,8 @@ curses - Tests that use curses and will modify the terminal's state and output modes. + lib2to3 - Run the tests for 2to3 (They take a while.) + largefile - It is okay to run some test that may create huge files. These tests can take a long time and may consume >2GB of disk space temporarily. @@ -173,8 +175,8 @@ from test import support -RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb', - 'decimal', 'compiler', 'subprocess', 'urlfetch') +RESOURCE_NAMES = ('audio', 'curses', 'lib2to3', 'largefile', 'network', + 'bsddb', 'decimal', 'compiler', 'subprocess', 'urlfetch') def usage(msg): diff --git a/Lib/test/test_audioop.py b/Lib/test/test_audioop.py index d43159a299b..689b0de7de7 100644 --- a/Lib/test/test_audioop.py +++ b/Lib/test/test_audioop.py @@ -163,6 +163,10 @@ def test_getsample(self): self.assertEqual(audioop.getsample(data[1], 2, i), i) self.assertEqual(audioop.getsample(data[2], 4, i), i) + def test_negavitelen(self): + # from issue 3306, previously it segfaulted + self.assertRaises(audioop.error, + audioop.findmax, ''.join(chr(x) for x in range(256)), -2392392) def test_main(): run_unittest(TestAudioop) diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py index 4646f02ac16..366ab7a16fe 100644 --- a/Lib/test/test_bz2.py +++ b/Lib/test/test_bz2.py @@ -120,6 +120,17 @@ def testIterator(self): self.assertEqual(list(iter(bz2f)), sio.readlines()) bz2f.close() + def testClosedIteratorDeadlock(self): + # "Test that iteration on a closed bz2file releases the lock." + # http://bugs.python.org/issue3309 + self.createTempFile() + bz2f = BZ2File(self.filename) + bz2f.close() + self.assertRaises(ValueError, bz2f.__next__) + # This call will deadlock of the above .__next__ call failed to + # release the lock. + self.assertRaises(ValueError, bz2f.readlines) + def testWrite(self): # "Test BZ2File.write()" bz2f = BZ2File(self.filename, "w") diff --git a/Lib/test/test_fractions.py b/Lib/test/test_fractions.py index 3c8da77ae8b..4f8defb81ae 100644 --- a/Lib/test/test_fractions.py +++ b/Lib/test/test_fractions.py @@ -62,11 +62,11 @@ def testInit(self): self.assertRaisesMessage(ZeroDivisionError, "Fraction(12, 0)", F, 12, 0) - self.assertRaises(AttributeError, F, 1.5) - self.assertRaises(AttributeError, F, 1.5 + 3j) + self.assertRaises(TypeError, F, 1.5) + self.assertRaises(TypeError, F, 1.5 + 3j) - self.assertRaises(AttributeError, F, F(1, 2), 3) - self.assertRaises(AttributeError, F, "3/2", 3) + self.assertRaises(TypeError, F, F(1, 2), 3) + self.assertRaises(TypeError, F, "3/2", 3) def testFromString(self): self.assertEquals((5, 1), _components(F("5"))) diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py index 4c5f7a58a1b..5f5c58871f9 100644 --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + # # Unit tests for the multiprocessing package # diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index cd8f56524de..f3c72e7c935 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -336,21 +336,6 @@ def test_sys_flags(self): def test_clear_type_cache(self): sys._clear_type_cache() - def test_compact_freelists(self): - sys._compact_freelists() - r = sys._compact_freelists() - ## freed blocks shouldn't change - #self.assertEqual(r[0][2], 0) - ## fill freelists - #ints = list(range(10000)) - #floats = [float(i) for i in ints] - #del ints - #del floats - ## should free more than 100 blocks - #r = sys._compact_freelists() - #self.assert_(r[0][1] > 100, r[0][1]) - #self.assert_(r[0][2] > 100, r[0][2]) - def test_ioencoding(self): import subprocess,os env = dict(os.environ) diff --git a/Misc/ACKS b/Misc/ACKS index dbb2035fac0..7ce335ef50d 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -145,6 +145,7 @@ Alex Coventry Matthew Dixon Cowles Christopher A. Craig Laura Creighton +Simon Cross Drew Csillag John Cugini Tom Culliton diff --git a/Modules/Setup.dist b/Modules/Setup.dist index a790556aa05..d2c89711a81 100644 --- a/Modules/Setup.dist +++ b/Modules/Setup.dist @@ -228,9 +228,11 @@ _symtable symtablemodule.c #_md5 md5module.c md5.c -# The _sha module implements the SHA checksum algorithm. -# (NIST's Secure Hash Algorithm.) +# The _sha module implements the SHA checksum algorithms. +# (NIST's Secure Hash Algorithms.) #_sha shamodule.c +#_sha256 sha256module.c +#_sha512 sha512module.c # The _tkinter module. diff --git a/Modules/_fileio.c b/Modules/_fileio.c index 71553ba06df..f520f0c701f 100644 --- a/Modules/_fileio.c +++ b/Modules/_fileio.c @@ -278,7 +278,6 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) ret = -1; done: - PyMem_Free(name); return ret; } diff --git a/Modules/audioop.c b/Modules/audioop.c index c660501ed8e..c54e51255bd 100644 --- a/Modules/audioop.c +++ b/Modules/audioop.c @@ -575,7 +575,7 @@ audioop_findmax(PyObject *self, PyObject *args) } len1 >>= 1; - if ( len1 < len2 ) { + if ( len2 < 0 || len1 < len2 ) { PyErr_SetString(AudioopError, "Input sample should be longer"); return 0; } diff --git a/Modules/bz2module.c b/Modules/bz2module.c index db10f31a2ee..562198be05b 100644 --- a/Modules/bz2module.c +++ b/Modules/bz2module.c @@ -1264,6 +1264,7 @@ BZ2File_iternext(BZ2FileObject *self) PyBytesObject* ret; ACQUIRE_LOCK(self); if (self->mode == MODE_CLOSED) { + RELEASE_LOCK(self); PyErr_SetString(PyExc_ValueError, "I/O operation on closed file"); return NULL; diff --git a/Modules/cmathmodule.c b/Modules/cmathmodule.c index eec618ecfc3..67df5c339bc 100644 --- a/Modules/cmathmodule.c +++ b/Modules/cmathmodule.c @@ -839,8 +839,10 @@ cmath_log(PyObject *self, PyObject *args) errno = 0; PyFPE_START_PROTECT("complex function", return 0) x = c_log(x); - if (PyTuple_GET_SIZE(args) == 2) - x = c_quot(x, c_log(y)); + if (PyTuple_GET_SIZE(args) == 2) { + y = c_log(y); + x = c_quot(x, y); + } PyFPE_END_PROTECT(x) if (errno != 0) return math_error(); diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 1954d0c75bf..d2817fb92ef 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -641,8 +641,6 @@ time_mktime(PyObject *self, PyObject *tup) { struct tm buf; time_t tt; - tt = time(&tt); - buf = *localtime(&tt); if (!gettmarg(tup, &buf)) return NULL; tt = mktime(&buf); diff --git a/Objects/abstract.c b/Objects/abstract.c index 60a5e849cfd..f15883e668b 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1632,7 +1632,7 @@ PySequence_GetItem(PyObject *s, Py_ssize_t i) return m->sq_item(s, i); } - return type_error("'%.200s' object is unindexable", s); + return type_error("'%.200s' object does not support indexing", s); } PyObject * diff --git a/Python/ceval.c b/Python/ceval.c index ec279bf3396..c75caf68231 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -617,18 +617,20 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) COMPARE_OP is often followed by JUMP_IF_FALSE or JUMP_IF_TRUE. And, those opcodes are often followed by a POP_TOP. - Verifying the prediction costs a single high-speed test of register + Verifying the prediction costs a single high-speed test of a register variable against a constant. If the pairing was good, then the - processor has a high likelihood of making its own successful branch - prediction which results in a nearly zero overhead transition to the - next opcode. + processor's own internal branch predication has a high likelihood of + success, resulting in a nearly zero-overhead transition to the + next opcode. A successful prediction saves a trip through the eval-loop + including its two unpredictable branches, the HAS_ARG test and the + switch-case. Combined with the processor's internal branch prediction, + a successful PREDICT has the effect of making the two opcodes run as if + they were a single new opcode with the bodies combined. - A successful prediction saves a trip through the eval-loop including - its two unpredictable branches, the HAS_ARG test and the switch-case. - - If collecting opcode statistics, turn off prediction so that - statistics are accurately maintained (the predictions bypass - the opcode frequency counter updates). + If collecting opcode statistics, your choices are to either keep the + predictions turned-on and interpret the results as if some opcodes + had been combined or turn-off predictions so that the opcode frequency + counter updates for both opcodes. */ #ifdef DYNAMIC_EXECUTION_PROFILE diff --git a/Python/pythonrun.c b/Python/pythonrun.c index d13563ffb35..3a6cc9120cb 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -229,14 +229,14 @@ Py_InitializeEx(int install_sigs) if (install_sigs) initsigs(); /* Signal handling stuff, including initintr() */ - /* Initialize warnings. */ - _PyWarnings_Init(); - if (PySys_HasWarnOptions()) { - PyObject *warnings_module = PyImport_ImportModule("warnings"); - if (!warnings_module) - PyErr_Clear(); - Py_XDECREF(warnings_module); - } + /* Initialize warnings. */ + _PyWarnings_Init(); + if (PySys_HasWarnOptions()) { + PyObject *warnings_module = PyImport_ImportModule("warnings"); + if (!warnings_module) + PyErr_Clear(); + Py_XDECREF(warnings_module); + } initmain(); /* Module __main__ */ if (!Py_NoSiteFlag) @@ -1246,7 +1246,7 @@ PyErr_PrintEx(int set_sys_last_vars) PyException_SetTraceback(v, tb); if (exception == NULL) return; - /* Now we know v != NULL too */ + /* Now we know v != NULL too */ if (set_sys_last_vars) { PySys_SetObject("last_type", exception); PySys_SetObject("last_value", v); @@ -2096,14 +2096,14 @@ PyRun_AnyFileFlags(FILE *fp, const char *name, PyCompilerFlags *flags) PyAPI_FUNC(PyObject *) PyRun_File(FILE *fp, const char *p, int s, PyObject *g, PyObject *l) { - return PyRun_FileExFlags(fp, p, s, g, l, 0, NULL); + return PyRun_FileExFlags(fp, p, s, g, l, 0, NULL); } #undef PyRun_FileEx PyAPI_FUNC(PyObject *) PyRun_FileEx(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, int c) { - return PyRun_FileExFlags(fp, p, s, g, l, c, NULL); + return PyRun_FileExFlags(fp, p, s, g, l, c, NULL); } #undef PyRun_FileFlags @@ -2111,7 +2111,7 @@ PyAPI_FUNC(PyObject *) PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, PyCompilerFlags *flags) { - return PyRun_FileExFlags(fp, p, s, g, l, 0, flags); + return PyRun_FileExFlags(fp, p, s, g, l, 0, flags); } #undef PyRun_SimpleFile