summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/conf.py85
-rw-r--r--Doc/howto/curses.rst6
-rw-r--r--Doc/library/collections.rst3
-rw-r--r--Doc/library/itertools.rst11
-rw-r--r--Doc/library/msilib.rst2
-rw-r--r--Doc/library/queue.rst7
-rw-r--r--Doc/library/sched.rst35
-rw-r--r--Doc/library/smtplib.rst26
-rw-r--r--Doc/library/socket.rst2
-rw-r--r--Doc/tools/sphinx-build.py13
-rw-r--r--Doc/tools/sphinxext/download.html53
-rw-r--r--Doc/tools/sphinxext/indexcontent.html56
-rw-r--r--Doc/tools/sphinxext/indexsidebar.html19
-rw-r--r--Doc/whatsnew/2.6.rst124
-rw-r--r--Lib/decimal.py6
-rwxr-xr-xLib/pdb.py2
-rw-r--r--Lib/sched.py31
-rwxr-xr-xLib/smtplib.py48
-rw-r--r--Lib/test/test_itertools.py3
-rw-r--r--Lib/test/test_queue.py46
-rw-r--r--Modules/_ctypes/libffi/src/x86/ffi_darwin.c2
-rw-r--r--Modules/_elementtree.c10
-rw-r--r--Modules/_struct.c3
-rw-r--r--Modules/itertoolsmodule.c7
-rw-r--r--Modules/main.c1
-rw-r--r--Modules/zipimport.c2
-rw-r--r--Parser/pgen.c1
-rw-r--r--Python/traceback.c3
-rw-r--r--setup.py10
29 files changed, 538 insertions, 79 deletions
diff --git a/Doc/conf.py b/Doc/conf.py
index 29137e2..5be5d1e 100644
--- a/Doc/conf.py
+++ b/Doc/conf.py
@@ -2,22 +2,28 @@
#
# Python documentation build configuration file
#
+# This file is execfile()d with the current directory set to its containing dir.
+#
# The contents of this file are pickled, so don't put values in the namespace
# that aren't pickleable (module imports are okay, they're removed automatically).
# General configuration
# ---------------------
+# General substitutions.
+project = 'Python'
+copyright = '1990-2007, Python Software Foundation'
+
# The default replacements for |version| and |release|.
-# If 'auto', Sphinx looks for the Include/patchlevel.h file in the current Python
+# If '<auto>', Sphinx looks for the Include/patchlevel.h file in the current Python
# source tree and replaces the values accordingly.
#
# The short X.Y version.
# version = '2.6'
-version = 'auto'
+version = '<auto>'
# The full version, including alpha/beta/rc tags.
# release = '2.6a0'
-release = 'auto'
+release = '<auto>'
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
@@ -39,6 +45,9 @@ unused_files = [
'library/xml.etree.rst',
]
+# Relative filename of the reference count data file.
+refcount_file = 'data/refcounts.dat'
+
# If true, '()' will be appended to :func: etc. cross-reference text.
add_function_parentheses = True
@@ -50,9 +59,6 @@ add_module_names = True
# Options for HTML output
# -----------------------
-# The base URL for download links.
-html_download_base_url = 'http://docs.python.org/ftp/python/doc/'
-
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
html_last_updated_fmt = '%b %d, %Y'
@@ -61,12 +67,71 @@ html_last_updated_fmt = '%b %d, %Y'
# typographically correct entities.
html_use_smartypants = True
+# Content template for the index page, filename relative to this file.
+html_index = 'tools/sphinxext/indexcontent.html'
+
+# Custom sidebar templates, filenames relative to this file.
+html_sidebars = {
+ 'index': 'tools/sphinxext/indexsidebar.html',
+}
+
+# Additional templates that should be rendered to pages.
+html_additional_pages = {
+ 'download': 'tools/sphinxext/download.html',
+}
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'pydoc'
+
# Options for LaTeX output
# ------------------------
-# The paper size ("letter" or "a4").
-latex_paper_size = "a4"
+# The paper size ('letter' or 'a4').
+latex_paper_size = 'a4'
+
+# The font size ('10pt', '11pt' or '12pt').
+latex_font_size = '10pt'
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, document class [howto/manual]).
+_stdauthor = r'Guido van Rossum\\Fred L. Drake, Jr., editor'
+latex_documents = [
+ ('c-api/index.rst', 'c-api.tex',
+ 'The Python/C API', _stdauthor, 'manual'),
+ ('distutils/index.rst', 'distutils.tex',
+ 'Distributing Python Modules', _stdauthor, 'manual'),
+ ('documenting/index.rst', 'documenting.tex',
+ 'Documenting Python', 'Georg Brandl', 'manual'),
+ ('extending/index.rst', 'extending.tex',
+ 'Extending and Embedding Python', _stdauthor, 'manual'),
+ ('install/index.rst', 'install.tex',
+ 'Installing Python Modules', _stdauthor, 'manual'),
+ ('library/index.rst', 'library.tex',
+ 'The Python Library Reference', _stdauthor, 'manual'),
+ ('reference/index.rst', 'reference.tex',
+ 'The Python Language Reference', _stdauthor, 'manual'),
+ ('tutorial/index.rst', 'tutorial.tex',
+ 'Python Tutorial', _stdauthor, 'manual'),
+ ('using/index.rst', 'using.tex',
+ 'Using Python', _stdauthor, 'manual'),
+ ('whatsnew/' + version + '.rst', 'whatsnew.tex',
+ 'What\'s New in Python', 'A. M. Kuchling', 'howto'),
+]
+# Collect all HOWTOs individually
+import os
+latex_documents.extend(('howto/' + fn, 'howto-' + fn[:-4] + '.tex',
+ 'HOWTO', _stdauthor, 'howto')
+ for fn in os.listdir('howto')
+ if fn.endswith('.rst') and fn != 'index.rst')
+
+# Additional stuff for the LaTeX preamble.
+latex_preamble = r'''
+\authoraddress{
+ \strong{Python Software Foundation}\\
+ Email: \email{docs@python.org}
+}
+'''
-# The font size ("10pt", "11pt" or "12pt").
-latex_font_size = "10pt"
+# Documents to append as an appendix to all manuals.
+latex_appendices = ['glossary.rst', 'about.rst', 'license.rst', 'copyright.rst']
diff --git a/Doc/howto/curses.rst b/Doc/howto/curses.rst
index 6f53708..12fb936 100644
--- a/Doc/howto/curses.rst
+++ b/Doc/howto/curses.rst
@@ -3,7 +3,7 @@
**********************************
:Author: A.M. Kuchling, Eric S. Raymond
-:Release: 2.02
+:Release: 2.03
.. topic:: Abstract
@@ -367,8 +367,8 @@ It's possible to change this behavior with the method :meth:`nodelay`. After
``nodelay(1)``, :meth:`getch` for the window becomes non-blocking and returns
``curses.ERR`` (a value of -1) when no input is ready. There's also a
:func:`halfdelay` function, which can be used to (in effect) set a timer on each
-:meth:`getch`; if no input becomes available within the number of milliseconds
-specified as the argument to :func:`halfdelay`, curses raises an exception.
+:meth:`getch`; if no input becomes available within a specified
+delay (measured in tenths of a second), curses raises an exception.
The :meth:`getch` method returns an integer; if it's between 0 and 255, it
represents the ASCII code of the key pressed. Values greater than 255 are
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index f1a8fff..cbc9c6b 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -566,6 +566,9 @@ faster versions that bypass error-checking::
def _replace(self, _map=map, **kwds):
return self._make(_map(kwds.get, ('x', 'y'), self))
+The subclasses shown above set ``__slots__`` to an empty tuple. This keeps
+keep memory requirements low by preventing the creation of instance dictionaries.
+
Subclassing is not useful for adding new, stored fields. Instead, simply
create a new named tuple type from the :attr:`_fields` attribute::
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index 21f6476..ca2b1ff 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -319,16 +319,19 @@ loops that truncate the stream.
.. function:: starmap(function, iterable)
- Make an iterator that computes the function using arguments tuples obtained from
+ Make an iterator that computes the function using arguments obtained from
the iterable. Used instead of :func:`imap` when argument parameters are already
grouped in tuples from a single iterable (the data has been "pre-zipped"). The
difference between :func:`imap` and :func:`starmap` parallels the distinction
between ``function(a,b)`` and ``function(*c)``. Equivalent to::
def starmap(function, iterable):
- iterable = iter(iterable)
- while True:
- yield function(*next(iterable))
+ for args in iterable:
+ yield function(*args)
+
+ .. versionchanged:: 2.6
+ Previously, :func:`starmap` required the function arguments to be tuples.
+ Now, any iterable is allowed.
.. function:: takewhile(predicate, iterable)
diff --git a/Doc/library/msilib.rst b/Doc/library/msilib.rst
index 93e7b84..35e472c 100644
--- a/Doc/library/msilib.rst
+++ b/Doc/library/msilib.rst
@@ -146,7 +146,7 @@ Database Objects
.. seealso::
- `MSIOpenView <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msiopenview.asp>`_
+ `MSIDatabaseOpenView <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msidatabaseopenview.asp>`_
`MSIDatabaseCommit <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msidatabasecommit.asp>`_
`MSIGetSummaryInformation <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msigetsummaryinformation.asp>`_
diff --git a/Doc/library/queue.rst b/Doc/library/queue.rst
index 5442a76..582f2cd 100644
--- a/Doc/library/queue.rst
+++ b/Doc/library/queue.rst
@@ -29,6 +29,7 @@ The :mod:`Queue` module defines the following classes and exceptions:
block once this size has been reached, until queue items are consumed. If
*maxsize* is less than or equal to zero, the queue size is infinite.
+
.. class:: LifoQueue(maxsize)
Constructor for a LIFO queue. *maxsize* is an integer that sets the upperbound
@@ -36,6 +37,9 @@ The :mod:`Queue` module defines the following classes and exceptions:
block once this size has been reached, until queue items are consumed. If
*maxsize* is less than or equal to zero, the queue size is infinite.
+ .. versionadded:: 2.6
+
+
.. class:: PriorityQueue(maxsize)
Constructor for a priority queue. *maxsize* is an integer that sets the upperbound
@@ -47,6 +51,9 @@ The :mod:`Queue` module defines the following classes and exceptions:
one returned by ``sorted(list(entries))[0]``). A typical pattern for entries
is a tuple in the form: ``(priority_number, data)``.
+ .. versionadded:: 2.6
+
+
.. exception:: Empty
Exception raised when non-blocking :meth:`get` (or :meth:`get_nowait`) is called
diff --git a/Doc/library/sched.rst b/Doc/library/sched.rst
index 57f9b5c..5dfa456 100644
--- a/Doc/library/sched.rst
+++ b/Doc/library/sched.rst
@@ -41,13 +41,39 @@ Example::
From print_time 930343700.273
930343700.276
+In multi-threaded environments, the :class:`scheduler` class has limitations
+with respect to thread-safety, inability to insert a new task before
+the one currently pending in a running scheduler, and holding up the main
+thread until the event queue is empty. Instead, the preferred approach
+is to use the :class:`threading.Timer` class instead.
+
+Example::
+
+ >>> import time
+ >>> from threading import Timer
+ >>> def print_time():
+ ... print "From print_time", time.time()
+ ...
+ >>> def print_some_times():
+ ... print time.time()
+ ... Timer(5, print_time, ()).start()
+ ... Timer(10, print_time, ()).start()
+ ... time.sleep(11) # sleep while time-delay events execute
+ ... print time.time()
+ ...
+ >>> print_some_times()
+ 930343690.257
+ From print_time 930343695.274
+ From print_time 930343700.273
+ 930343701.301
+
.. _scheduler-objects:
Scheduler Objects
-----------------
-:class:`scheduler` instances have the following methods:
+:class:`scheduler` instances have the following methods and attributes:
.. method:: scheduler.enterabs(time, priority, action, argument)
@@ -98,3 +124,10 @@ Scheduler Objects
the calling code is responsible for canceling events which are no longer
pertinent.
+.. attribute:: scheduler.queue
+
+ Read-only attribute returning a list of upcoming events in the order they
+ will be run. Each event is shown as a :term:`named tuple` with the
+ following fields: time, priority, action, argument.
+
+ .. versionadded:: 2.6
diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst
index 790cacb..1ffe812 100644
--- a/Doc/library/smtplib.rst
+++ b/Doc/library/smtplib.rst
@@ -184,6 +184,16 @@ An :class:`SMTP` instance has the following methods:
necessary to call this method explicitly. It will be implicitly called by
:meth:`sendmail` when necessary.
+.. method:: SMTP.ehlo_or_helo_if_needed()
+
+ This method call :meth:`ehlo` and or :meth:`helo` if there has been no
+ previous ``EHLO`` or ``HELO`` command this session. It tries ESMTP ``EHLO``
+ first.
+
+ :exc:SMTPHeloError
+ The server didn't reply properly to the ``HELO`` greeting.
+
+ .. versionadded:: 2.6
.. method:: SMTP.has_extn(name)
@@ -230,6 +240,22 @@ An :class:`SMTP` instance has the following methods:
If *keyfile* and *certfile* are provided, these are passed to the :mod:`socket`
module's :func:`ssl` function.
+ If there has been no previous ``EHLO`` or ``HELO`` command this session,
+ this method tries ESMTP ``EHLO`` first.
+
+ .. versionchanged:: 2.6
+
+ :exc:`SMTPHeloError`
+ The server didn't reply properly to the ``HELO`` greeting.
+
+ :exc:`SMTPException`
+ The server does not support the STARTTLS extension.
+
+ .. versionchanged:: 2.6
+
+ :exc:`RuntimeError`
+ SSL/TLS support is not available to your python interpreter.
+
.. method:: SMTP.sendmail(from_addr, to_addrs, msg[, mail_options, rcpt_options])
diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst
index 406c136..7d2dea0 100644
--- a/Doc/library/socket.rst
+++ b/Doc/library/socket.rst
@@ -562,7 +562,7 @@ correspond to Unix system calls applicable to sockets.
:platform: Windows
- The `meth:ioctl` method is a limited interface to the WSAIoctl system
+ The :meth:`ioctl` method is a limited interface to the WSAIoctl system
interface. Please refer to the MSDN documentation for more information.
diff --git a/Doc/tools/sphinx-build.py b/Doc/tools/sphinx-build.py
index ab9f40d..d72a831 100644
--- a/Doc/tools/sphinx-build.py
+++ b/Doc/tools/sphinx-build.py
@@ -11,12 +11,13 @@ import sys
if __name__ == '__main__':
- if not (2, 5, 1) <= sys.version_info[:3] < (3, 0, 0):
- sys.stderr.write("""\
-Error: Sphinx needs to be executed with Python 2.5.1 or newer (not 3.0 though).
-If you run this from the Makefile, you can set the PYTHON variable to the path
-of an alternative interpreter executable, e.g., ``make html PYTHON=python2.5``.)
-""")
+ if sys.version_info[:3] < (2, 4, 0):
+ print("""\
+Error: Sphinx needs to be executed with Python 2.4 or newer (not 3.0 though).
+(If you run this from the Makefile, you can set the PYTHON variable
+to the path of an alternative interpreter executable, e.g.,
+``make html PYTHON=python2.5``).
+""", file=sys.stderr)
sys.exit(1)
from sphinx import main
diff --git a/Doc/tools/sphinxext/download.html b/Doc/tools/sphinxext/download.html
new file mode 100644
index 0000000..f6a593a
--- /dev/null
+++ b/Doc/tools/sphinxext/download.html
@@ -0,0 +1,53 @@
+{% extends "layout.html" %}
+{% set title = 'Download' %}
+{% block body %}
+
+<h1>Download Python {{ release }} Documentation
+ {%- if last_updated %} (last updated on {{ last_updated }}){% endif %}</h1>
+
+<p>To download an archive containing all the documents for this version of
+Python in one of various formats, follow one of links in this table. The numbers
+in the table are the size of the download files in Kilobytes.</p>
+
+{# XXX download links #}
+
+
+<p>These archives contain all the content in the documentation section.</p>
+
+<h2>Unpacking</h2>
+
+<p>Unix users should download the .tar.bz2 archives; these are bzipped tar
+archives and can be handled in the usual way using tar and the bzip2
+program. The <a href="http://www.info-zip.org">InfoZIP</a> unzip program can be
+used to handle the ZIP archives if desired. The .tar.bz2 archives provide the
+best compression and fastest download times.</p>
+
+<p>Windows users can use the ZIP archives since those are customary on that
+platform. These are created on Unix using the InfoZIP zip program. They may be
+unpacked using the free WiZ tool (from the InfoZIP developers) or any other
+tool for handling ZIP archives; any of them should work.</p>
+
+<p>Note that the .tar.bz2 files are smaller than the other archives; Windows
+users may want to install the bzip2 tools on their systems as well. Windows
+binaries for a command-line tool are available at <a
+href="http://www.bzip.org">The bzip2 and libbzip2 official home page</a>, but
+most other archiving utilities support the tar and bzip2 formats as well.</p>
+
+
+<h2>Problems</h2>
+
+<p><strong>Printing PDFs using Adobe Acrobat Reader 5.0:</strong> Adobe has
+reportedly admitted that there is a bug in Acrobat Reader 5.0 which causes it
+not to print at least some PDF files generated by pdfTeX. This software is used
+to produce the PDF version of the Python documentation, and our documents
+definately trigger this bug in Acrobat Reader. To print the PDF files, use
+Acrobat Reader 4.x, ghostscript, or xpdf.</p>
+
+<p>Reportedly, Acrobat Reader 6.0 can print these documents without this
+problem, but we've not yet had an opportunity to confirm the report. Sadly,
+version 6.0 is not yet available on Unix platforms.</p>
+
+<p>If you have comments or suggestions for the Python documentation, please send
+email to <a href="docs@python.org">docs@python.org</a>.</p>
+
+{% endblock %}
diff --git a/Doc/tools/sphinxext/indexcontent.html b/Doc/tools/sphinxext/indexcontent.html
new file mode 100644
index 0000000..218f346
--- /dev/null
+++ b/Doc/tools/sphinxext/indexcontent.html
@@ -0,0 +1,56 @@
+ <p><strong>Parts of the documentation:</strong></p>
+ <table class="contentstable" align="center"><tr>
+ <td width="50%">
+ <p class="biglink"><a class="biglink" href="{{ pathto("whatsnew/" + version) }}">What's new in Python {{ version }}?</a><br>
+ <span class="linkdescr">changes since previous major release</span></p>
+ <p class="biglink"><a class="biglink" href="{{ pathto("tutorial/index") }}">Tutorial</a><br>
+ <span class="linkdescr">start here</span></p>
+ <p class="biglink"><a class="biglink" href="{{ pathto("using/index") }}">Using Python</a><br>
+ <span class="linkdescr">how to use Python on different platforms</span></p>
+ <p class="biglink"><a class="biglink" href="{{ pathto("reference/index") }}">Language Reference</a><br>
+ <span class="linkdescr">describes syntax and language elements</span></p>
+ <p class="biglink"><a class="biglink" href="{{ pathto("library/index") }}">Library Reference</a><br>
+ <span class="linkdescr">keep this under your pillow</span></p>
+ <p class="biglink"><a class="biglink" href="{{ pathto("howto/index") }}">Python HOWTOs</a><br>
+ <span class="linkdescr">in-depth documents on specific topics</span></p>
+ </td><td width="50%">
+ <p class="biglink"><a class="biglink" href="{{ pathto("extending/index") }}">Extending and Embedding</a><br>
+ <span class="linkdescr">tutorial for C/C++ programmers</span></p>
+ <p class="biglink"><a class="biglink" href="{{ pathto("c-api/index") }}">Python/C API</a><br>
+ <span class="linkdescr">reference for C/C++ programmers</span></p>
+ <p class="biglink"><a class="biglink" href="{{ pathto("install/index") }}">Installing Python Modules</a><br>
+ <span class="linkdescr">information for installers &amp; sys-admins</span></p>
+ <p class="biglink"><a class="biglink" href="{{ pathto("distutils/index") }}">Distributing Python Modules</a><br>
+ <span class="linkdescr">sharing modules with others</span></p>
+ <p class="biglink"><a class="biglink" href="{{ pathto("documenting/index") }}">Documenting Python</a><br>
+ <span class="linkdescr">guide for documentation authors</span></p>
+ </td></tr>
+ </table>
+
+ <p><strong>Indices and tables:</strong></p>
+ <table class="contentstable" align="center"><tr>
+ <td width="50%">
+ <p class="biglink"><a class="biglink" href="{{ pathto("modindex") }}">Global Module Index</a><br>
+ <span class="linkdescr">quick access to all modules</span></p>
+ <p class="biglink"><a class="biglink" href="{{ pathto("genindex") }}">General Index</a><br>
+ <span class="linkdescr">all functions, classes, terms</span></p>
+ <p class="biglink"><a class="biglink" href="{{ pathto("glossary") }}">Glossary</a><br>
+ <span class="linkdescr">the most important terms explained</span></p>
+ </td><td width="50%">
+ <p class="biglink"><a class="biglink" href="{{ pathto("search") }}">Search page</a><br>
+ <span class="linkdescr">search this documentation</span></p>
+ <p class="biglink"><a class="biglink" href="{{ pathto("contents") }}">Complete Table of Contents</a><br>
+ <span class="linkdescr">lists all sections and subsections</span></p>
+ </td></tr>
+ </table>
+
+ <p><strong>Meta information:</strong></p>
+ <table class="contentstable" align="center"><tr>
+ <td width="50%">
+ <p class="biglink"><a class="biglink" href="{{ pathto("bugs") }}">Reporting bugs</a></p>
+ <p class="biglink"><a class="biglink" href="{{ pathto("about") }}">About the documentation</a></p>
+ </td><td width="50%">
+ <p class="biglink"><a class="biglink" href="{{ pathto("license") }}">History and License of Python</a></p>
+ <p class="biglink"><a class="biglink" href="{{ pathto("copyright") }}">Copyright</a></p>
+ </td></tr>
+ </table>
diff --git a/Doc/tools/sphinxext/indexsidebar.html b/Doc/tools/sphinxext/indexsidebar.html
new file mode 100644
index 0000000..b74c54f
--- /dev/null
+++ b/Doc/tools/sphinxext/indexsidebar.html
@@ -0,0 +1,19 @@
+ <h3>Download</h3>
+ <p><a href="{{ pathto('download') }}">Download these documents</a></p>
+ <h3>Other resources</h3>
+ <ul>
+ {# XXX: many of these should probably be merged in the main docs #}
+ <li><a href="http://www.python.org/doc/faq/">FAQs</a></li>
+ <li><a href="http://www.python.org/doc/intros/">Introductions</a></li>
+ <li><a href="http://www.python.org/doc/essays/">Guido's Essays</a></li>
+ <li><a href="http://www.python.org/doc/newstyle/">New-style Classes</a></li>
+ <li><a href="http://www.python.org/dev/peps/">PEP Index</a></li>
+ <li><a href="http://wiki.python.org/moin/BeginnersGuide">Beginner's Guide</a></li>
+ <li><a href="http://www.python.org/topics/">Topic Guides</a></li>
+ <li><a href="http://wiki.python.org/moin/PythonBooks">Book List</a></li>
+ <li><a href="http://www.python.org/doc/av/">Audio/Visual Talks</a></li>
+ <li><a href="http://www.python.org/doc/other/">Other Doc Collections</a></li>
+ <li>&nbsp;</li>
+ <li><a href="http://www.python.org/doc/versions/">Previous versions</a></li>
+ <li>&nbsp;</li>
+ </ul>
diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst
index 0539a44..46922a4 100644
--- a/Doc/whatsnew/2.6.rst
+++ b/Doc/whatsnew/2.6.rst
@@ -541,6 +541,90 @@ an abstract method.
Implemented by XXX.
Backported to 2.6 by Benjamin Aranguren, with Alex Martelli.
+.. ======================================================================
+
+.. _pep-3141:
+
+PEP 3141: A Type Hierarchy for Numbers
+=====================================================
+
+In Python 3.0, several abstract base classes for numeric types,
+inspired by Scheme's numeric tower, are being added.
+This change was backported to 2.6 as the :mod:`numbers` module.
+
+The most general ABC is :class:`Number`. It defines no operations at
+all, and only exists to allow checking if an object is a number by
+doing ``isinstance(obj, Number)``.
+
+Numbers are further divided into :class:`Exact` and :class:`Inexact`.
+Exact numbers can represent values precisely and operations never
+round off the results or introduce tiny errors that may break the
+communtativity and associativity properties; inexact numbers may
+perform such rounding or introduce small errors. Integers, long
+integers, and rational numbers are exact, while floating-point
+and complex numbers are inexact.
+
+:class:`Complex` is a subclass of :class:`Number`. Complex numbers
+can undergo the basic operations of addition, subtraction,
+multiplication, division, and exponentiation, and you can retrieve the
+real and imaginary parts and obtain a number's conjugate. Python's built-in
+complex type is an implementation of :class:`Complex`.
+
+:class:`Real` further derives from :class:`Complex`, and adds
+operations that only work on real numbers: :func:`floor`, :func:`trunc`,
+rounding, taking the remainder mod N, floor division,
+and comparisons.
+
+:class:`Rational` numbers derive from :class:`Real`, have
+:attr:`numerator` and :attr:`denominator` properties, and can be
+converted to floats. Python 2.6 adds a simple rational-number class
+in the :mod:`rational` module.
+
+:class:`Integral` numbers derive from :class:`Rational`, and
+can be shifted left and right with ``<<`` and ``>>``,
+combined using bitwise operations such as ``&`` and ``|``,
+and can be used as array indexes and slice boundaries.
+
+In Python 3.0, the PEP slightly redefines the existing built-ins
+:func:`math.floor`, :func:`math.ceil`, :func:`round`, and adds a new
+one, :func:`trunc`, that's been backported to Python 2.6.
+:func:`trunc` rounds toward zero, returning the closest
+:class:`Integral` that's between the function's argument and zero.
+
+.. seealso::
+
+ XXX link: Discusses Scheme's numeric tower.
+
+
+
+The Rational Module
+--------------------------------------------------
+
+To fill out the hierarchy of numeric types, a rational-number class
+has been added as the :mod:`rational` module. Rational numbers are
+represented as a fraction; rational numbers can exactly represent
+numbers such as two-thirds that floating-point numbers can only
+approximate.
+
+The :class:`Rational` constructor takes two :class:`Integral` values
+that will be the numerator and denominator of the resulting fraction. ::
+
+ >>> from rational import Rational
+ >>> a = Rational(2, 3)
+ >>> b = Rational(2, 5)
+ >>> float(a), float(b)
+ (0.66666666666666663, 0.40000000000000002)
+ >>> a+b
+ rational.Rational(16,15)
+ >>> a/b
+ rational.Rational(5,3)
+
+The :mod:`rational` module is based upon an implementation by Sjoerd
+Mullender that was in Python's :file:`Demo/classes/` directory for a
+long time. This implementation was significantly updated by Jeffrey
+Yaskin.
+
+
Other Language Changes
======================
@@ -568,10 +652,10 @@ Here are all of the changes that Python 2.6 makes to the core Python language.
.. Revision 57619
-* Properties now have two attributes,
+* Properties now have three attributes, :attr:`getter`,
:attr:`setter` and :attr:`deleter`, that are useful shortcuts for
- adding a setter or deleter function to an existing property.
- You would use them like this::
+ adding or modifying a getter, setter or deleter function to an
+ existing property. You would use them like this::
class C(object):
@property
@@ -586,6 +670,15 @@ Here are all of the changes that Python 2.6 makes to the core Python language.
def x(self):
del self._x
+ class D(C):
+ @C.x.getter
+ def x(self):
+ return self._x * 2
+
+ @x.setter
+ def x(self, value):
+ self._x = value / 2
+
* C functions and methods that use
:cfunc:`PyComplex_AsCComplex` will now accept arguments that
@@ -997,6 +1090,12 @@ complete list of changes, or look through the CVS logs for all the details.
.. Patch #957003
+* In the :mod:`smtplib` module, SMTP.starttls() now complies with :rfc:`3207`
+ and forgets any knowledge obtained from the server not obtained from
+ the TLS negotiation itself. Patch contributed by Bill Fenner.
+
+ .. Issue 829951
+
* The :mod:`socket` module now supports TIPC (http://tipc.sf.net),
a high-performance non-IP-based protocol designed for use in clustered
environments. TIPC addresses are 4- or 5-tuples.
@@ -1246,13 +1345,30 @@ Port-Specific Changes: Windows
API. The :func:`getwch` function reads a keypress and returns a Unicode
value, as does the :func:`getwche` function. The :func:`putwch` function
takes a Unicode character and writes it to the console.
+ (Contributed by Christian Heimes.)
+
+* :func:`os.path.expandvars` will now expand environment variables
+ in the form "%var%", and "~user" will be expanded into the
+ user's home directory path. (Contributed by Josiah Carlson.)
+
+* The :mod:`socket` module's socket objects now have an
+ :meth:`ioctl` method that provides a limited interface to the
+ :cfunc:`WSAIoctl` system interface.
* The :mod:`_winreg` module now has a function,
:func:`ExpandEnvironmentStrings`,
that expands environment variable references such as ``%NAME%``
in an input string. The handle objects provided by this
module now support the context protocol, so they can be used
- in :keyword:`with` statements.
+ in :keyword:`with` statements. (Contributed by Christian Heimes.)
+
+* The new default compiler on Windows is Visual Studio 2008 (VS 9.0). The
+ build directories for Visual Studio 2003 (VS7.1) and 2005 (VS8.0)
+ were moved into the PC/ directory. The new PCbuild directory supports
+ cross compilation for X64, debug builds and Profile Guided Optimization
+ (PGO). PGO builds are roughly 10% faster than normal builds.
+ (Contributed by Christian Heimes with help from Amaury Forgeot d'Arc and
+ Martin von Loewis.)
.. ======================================================================
diff --git a/Lib/decimal.py b/Lib/decimal.py
index 5e1b16b..51758f2 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -2982,7 +2982,7 @@ class Decimal(_numbers.Real, _numbers.Inexact):
def _islogical(self):
"""Return True if self is a logical operand.
- For being logical, it must be a finite numbers with a sign of 0,
+ For being logical, it must be a finite number with a sign of 0,
an exponent of 0, and a coefficient whose digits must all be
either 0 or 1.
"""
@@ -4098,7 +4098,7 @@ class Context(object):
"""max compares two values numerically and returns the maximum.
If either operand is a NaN then the general rules apply.
- Otherwise, the operands are compared as as though by the compare
+ Otherwise, the operands are compared as though by the compare
operation. If they are numerically equal then the left-hand operand
is chosen as the result. Otherwise the maximum (closer to positive
infinity) of the two operands is chosen as the result.
@@ -4122,7 +4122,7 @@ class Context(object):
"""min compares two values numerically and returns the minimum.
If either operand is a NaN then the general rules apply.
- Otherwise, the operands are compared as as though by the compare
+ Otherwise, the operands are compared as though by the compare
operation. If they are numerically equal then the left-hand operand
is chosen as the result. Otherwise the minimum (closer to negative
infinity) of the two operands is chosen as the result.
diff --git a/Lib/pdb.py b/Lib/pdb.py
index dfd745d..57a2b45 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -198,6 +198,8 @@ class Pdb(bdb.Bdb, cmd.Cmd):
globals = self.curframe.f_globals
try:
code = compile(line + '\n', '<stdin>', 'single')
+ save_stdout = sys.stdout
+ save_stdin = sys.stdin
try:
sys.stdin = self.stdin
sys.stdout = self.stdout
diff --git a/Lib/sched.py b/Lib/sched.py
index 51c4e74..1c7bfea 100644
--- a/Lib/sched.py
+++ b/Lib/sched.py
@@ -29,14 +29,17 @@ has another way to reference private data (besides global variables).
# XXX the global state of your particular time and delay functions.
import heapq
+from collections import namedtuple
__all__ = ["scheduler"]
+Event = namedtuple('Event', 'time, priority, action, argument')
+
class scheduler:
def __init__(self, timefunc, delayfunc):
"""Initialize a new instance, passing the time and delay
functions"""
- self.queue = []
+ self._queue = []
self.timefunc = timefunc
self.delayfunc = delayfunc
@@ -47,8 +50,8 @@ class scheduler:
if necessary.
"""
- event = time, priority, action, argument
- heapq.heappush(self.queue, event)
+ event = Event(time, priority, action, argument)
+ heapq.heappush(self._queue, event)
return event # The ID
def enter(self, delay, priority, action, argument):
@@ -67,12 +70,12 @@ class scheduler:
If the event is not in the queue, this raises RuntimeError.
"""
- self.queue.remove(event)
- heapq.heapify(self.queue)
+ self._queue.remove(event)
+ heapq.heapify(self._queue)
def empty(self):
"""Check whether the queue is empty."""
- return not self.queue
+ return not self._queue
def run(self):
"""Execute events until the queue is empty.
@@ -97,7 +100,7 @@ class scheduler:
"""
# localize variable access to minimize overhead
# and to improve thread safety
- q = self.queue
+ q = self._queue
delayfunc = self.delayfunc
timefunc = self.timefunc
pop = heapq.heappop
@@ -115,3 +118,17 @@ class scheduler:
delayfunc(0) # Let other threads run
else:
heapq.heappush(event)
+
+ @property
+ def queue(self):
+ """An ordered list of upcoming events.
+
+ Events are named tuples with fields for:
+ time, priority, action, arguments
+
+ """
+ # Use heapq to sort the queue rather than using 'sorted(self._queue)'.
+ # With heapq, two events scheduled at the same time will show in
+ # the actual order they would be retrieved.
+ events = self._queue[:]
+ return map(heapq.heappop, [events]*len(events))
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index 0b4cbf0..2b7befb 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -495,6 +495,23 @@ class SMTP:
# some useful methods
+ def ehlo_or_helo_if_needed(self):
+ """Call self.ehlo() and/or self.helo() if needed.
+
+ If there has been no previous EHLO or HELO command this session, this
+ method tries ESMTP EHLO first.
+
+ This method may raise the following exceptions:
+
+ SMTPHeloError The server didn't reply properly to
+ the helo greeting.
+ """
+ if self.helo_resp is None and self.ehlo_resp is None:
+ if not (200 <= self.ehlo()[0] <= 299):
+ (code, resp) = self.helo()
+ if not (200 <= code <= 299):
+ raise SMTPHeloError(code, resp)
+
def login(self, user, password):
"""Log in on an SMTP server that requires authentication.
@@ -530,11 +547,7 @@ class SMTP:
AUTH_CRAM_MD5 = "CRAM-MD5"
AUTH_LOGIN = "LOGIN"
- if self.helo_resp is None and self.ehlo_resp is None:
- if not (200 <= self.ehlo()[0] <= 299):
- (code, resp) = self.helo()
- if not (200 <= code <= 299):
- raise SMTPHeloError(code, resp)
+ self.ehlo_or_helo_if_needed()
if not self.has_extn("auth"):
raise SMTPException("SMTP AUTH extension not supported by server.")
@@ -580,18 +593,37 @@ class SMTP:
def starttls(self, keyfile = None, certfile = None):
"""Puts the connection to the SMTP server into TLS mode.
+ If there has been no previous EHLO or HELO command this session, this
+ method tries ESMTP EHLO first.
+
If the server supports TLS, this will encrypt the rest of the SMTP
session. If you provide the keyfile and certfile parameters,
the identity of the SMTP server and client can be checked. This,
however, depends on whether the socket module really checks the
certificates.
+
+ This method may raise the following exceptions:
+
+ SMTPHeloError The server didn't reply properly to
+ the helo greeting.
"""
+ self.ehlo_or_helo_if_needed()
+ if not self.has_extn("starttls"):
+ raise SMTPException("STARTTLS extension not supported by server.")
(resp, reply) = self.docmd("STARTTLS")
if resp == 220:
if not _have_ssl:
raise RuntimeError("No SSL support included in this Python")
self.sock = ssl.wrap_socket(self.sock, keyfile, certfile)
self.file = SSLFakeFile(self.sock)
+ # RFC 3207:
+ # The client MUST discard any knowledge obtained from
+ # the server, such as the list of SMTP service extensions,
+ # which was not obtained from the TLS negotiation itself.
+ self.helo_resp = None
+ self.ehlo_resp = None
+ self.esmtp_features = {}
+ self.does_esmtp = 0
return (resp, reply)
def sendmail(self, from_addr, to_addrs, msg, mail_options=[],
@@ -651,11 +683,7 @@ class SMTP:
empty dictionary.
"""
- if self.helo_resp is None and self.ehlo_resp is None:
- if not (200 <= self.ehlo()[0] <= 299):
- (code,resp) = self.helo()
- if not (200 <= code <= 299):
- raise SMTPHeloError(code, resp)
+ self.ehlo_or_helo_if_needed()
esmtp_opts = []
if self.does_esmtp:
# Hmmm? what's this? -ddm
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index 17e0058..4c0af07 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -300,7 +300,8 @@ class TestBasicOps(unittest.TestCase):
self.assertEqual(take(3, starmap(operator.pow, izip(count(), count(1)))),
[0**1, 1**2, 2**3])
self.assertEqual(list(starmap(operator.pow, [])), [])
- self.assertRaises(TypeError, list, starmap(operator.pow, [[4,5]]))
+ self.assertEqual(list(starmap(operator.pow, [iter([4,5])])), [4**5])
+ self.assertRaises(TypeError, list, starmap(operator.pow, [None]))
self.assertRaises(TypeError, starmap)
self.assertRaises(TypeError, starmap, operator.pow, [(4,5)], 'extra')
self.assertRaises(TypeError, next, starmap(10, [(4,5)]))
diff --git a/Lib/test/test_queue.py b/Lib/test/test_queue.py
index 4d89ed2..e15ee39 100644
--- a/Lib/test/test_queue.py
+++ b/Lib/test/test_queue.py
@@ -184,28 +184,35 @@ def SimpleQueueTest(q):
raise RuntimeError("Call this function with an empty queue")
# I guess we better check things actually queue correctly a little :)
q.put(111)
+ q.put(333)
q.put(222)
- verify(q.get() == 111 and q.get() == 222,
+ target_order = dict(Queue = [111, 333, 222],
+ LifoQueue = [222, 333, 111],
+ PriorityQueue = [111, 222, 333])
+ actual_order = [q.get(), q.get(), q.get()]
+ verify(actual_order == target_order[q.__class__.__name__],
"Didn't seem to queue the correct data!")
for i in range(QUEUE_SIZE-1):
q.put(i)
verify(q.qsize(), "Queue should not be empty")
verify(not qfull(q), "Queue should not be full")
- q.put("last")
+ last = 2*QUEUE_SIZE
+ full = 3*2*QUEUE_SIZE
+ q.put(last)
verify(qfull(q), "Queue should be full")
try:
- q.put("full", block=0)
+ q.put(full, block=0)
raise TestFailed("Didn't appear to block with a full queue")
except Queue.Full:
pass
try:
- q.put("full", timeout=0.01)
+ q.put(full, timeout=0.01)
raise TestFailed("Didn't appear to time-out with a full queue")
except Queue.Full:
pass
# Test a blocking put
- _doBlockingTest(q.put, ("full",), q.get, ())
- _doBlockingTest(q.put, ("full", True, 10), q.get, ())
+ _doBlockingTest(q.put, (full,), q.get, ())
+ _doBlockingTest(q.put, (full, True, 10), q.get, ())
# Empty it
for i in range(QUEUE_SIZE):
q.get()
@@ -250,8 +257,7 @@ def QueueJoinTest(q):
q.put(i)
q.join()
verify(cum==sum(range(100)), "q.join() did not block until all tasks were done")
- for i in (0,1):
- q.put(None) # instruct the threads to close
+ q.put(None) # instruct the threads to close
q.join() # verify that you can join twice
def QueueTaskDoneTest(q):
@@ -263,18 +269,20 @@ def QueueTaskDoneTest(q):
raise TestFailed("Did not detect task count going negative")
def test():
- q = Queue.Queue()
- QueueTaskDoneTest(q)
- QueueJoinTest(q)
- QueueJoinTest(q)
- QueueTaskDoneTest(q)
+ for Q in Queue.Queue, Queue.LifoQueue, Queue.PriorityQueue:
+ q = Q()
+ QueueTaskDoneTest(q)
+ QueueJoinTest(q)
+ QueueJoinTest(q)
+ QueueTaskDoneTest(q)
+
+ q = Q(QUEUE_SIZE)
+ # Do it a couple of times on the same queue
+ SimpleQueueTest(q)
+ SimpleQueueTest(q)
+ if verbose:
+ print("Simple Queue tests seemed to work for", Q.__name__)
- q = Queue.Queue(QUEUE_SIZE)
- # Do it a couple of times on the same queue
- SimpleQueueTest(q)
- SimpleQueueTest(q)
- if verbose:
- print("Simple Queue tests seemed to work")
q = FailingQueue(QUEUE_SIZE)
FailingQueueTest(q)
FailingQueueTest(q)
diff --git a/Modules/_ctypes/libffi/src/x86/ffi_darwin.c b/Modules/_ctypes/libffi/src/x86/ffi_darwin.c
index c9742d8..71ac587 100644
--- a/Modules/_ctypes/libffi/src/x86/ffi_darwin.c
+++ b/Modules/_ctypes/libffi/src/x86/ffi_darwin.c
@@ -217,7 +217,7 @@ extern void ffi_call_STDCALL(void (*)(char *, extended_cif *),
#endif /* X86_WIN32 */
void ffi_call(/*@dependent@*/ ffi_cif *cif,
- void (*fn)(),
+ void (*fn)(void),
/*@out@*/ void *rvalue,
/*@dependent@*/ void **avalue)
{
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 97297b8..d237cbb 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -348,7 +348,17 @@ element_resize(ElementObject* self, int extra)
if (size > self->extra->allocated) {
/* use Python 2.4's list growth strategy */
size = (size >> 3) + (size < 9 ? 3 : 6) + size;
+ /* Coverity CID #182 size_error: Allocating 1 bytes to pointer "children"
+ * which needs at least 4 bytes.
+ * Although it's a false alarm always assume at least one child to
+ * be safe.
+ */
+ size = size ? size : 1;
if (self->extra->children != self->extra->_children) {
+ /* Coverity CID #182 size_error: Allocating 1 bytes to pointer
+ * "children", which needs at least 4 bytes. Although it's a
+ * false alarm always assume at least one child to be safe.
+ */
children = PyObject_Realloc(self->extra->children,
size * sizeof(PyObject*));
if (!children)
diff --git a/Modules/_struct.c b/Modules/_struct.c
index 278b035..dcf315e 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -1918,8 +1918,7 @@ PyDoc_STRVAR(clearcache_doc,
static PyObject *
clearcache(PyObject *self)
{
- if (cache != NULL)
- PyDict_Clear(cache);
+ Py_CLEAR(cache);
Py_RETURN_NONE;
}
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 132acc5..d35c6b9 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -1356,10 +1356,11 @@ starmap_next(starmapobject *lz)
if (args == NULL)
return NULL;
if (!PyTuple_CheckExact(args)) {
+ PyObject *newargs = PySequence_Tuple(args);
Py_DECREF(args);
- PyErr_SetString(PyExc_TypeError,
- "iterator must return a tuple");
- return NULL;
+ if (newargs == NULL)
+ return NULL;
+ args = newargs;
}
result = PyObject_Call(lz->func, args, NULL);
Py_DECREF(args);
diff --git a/Modules/main.c b/Modules/main.c
index 87462a0..ce05431 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -533,6 +533,7 @@ Py_Main(int argc, char **argv)
if (fstat(fileno(fp), &sb) == 0 &&
S_ISDIR(sb.st_mode)) {
fprintf(stderr, "%s: '%s' is a directory, cannot continue\n", argv[0], filename);
+ fclose(fp);
return 1;
}
}
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 84985a8..cd56be3 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -1000,6 +1000,8 @@ parse_dostime(int dostime, int dosdate)
{
struct tm stm;
+ memset((void *) &stm, '\0', sizeof(stm));
+
stm.tm_sec = (dostime & 0x1f) * 2;
stm.tm_min = (dostime >> 5) & 0x3f;
stm.tm_hour = (dostime >> 11) & 0x1f;
diff --git a/Parser/pgen.c b/Parser/pgen.c
index 76cb204..959a5d3 100644
--- a/Parser/pgen.c
+++ b/Parser/pgen.c
@@ -667,6 +667,7 @@ pgen(node *n)
g = maketables(gr);
translatelabels(g);
addfirstsets(g);
+ PyObject_FREE(gr);
return g;
}
diff --git a/Python/traceback.c b/Python/traceback.c
index 1a4ec1f..be55aa9 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -135,6 +135,8 @@ tb_displayline(PyObject *f, char *filename, int lineno, char *name)
FILE *xfp;
char linebuf[2000];
int i;
+ char namebuf[MAXPATHLEN+1];
+
if (filename == NULL || name == NULL)
return -1;
/* This is needed by Emacs' compile command */
@@ -153,7 +155,6 @@ tb_displayline(PyObject *f, char *filename, int lineno, char *name)
Py_ssize_t _npath = PyList_Size(path);
int npath = Py_SAFE_DOWNCAST(_npath, Py_ssize_t, int);
size_t taillen = strlen(tail);
- char namebuf[MAXPATHLEN+1];
for (i = 0; i < npath; i++) {
PyObject *v = PyList_GetItem(path, i);
if (v == NULL) {
diff --git a/setup.py b/setup.py
index 450bf5d..4c51bab 100644
--- a/setup.py
+++ b/setup.py
@@ -101,8 +101,14 @@ class PyBuildExt(build_ext):
missing = self.detect_modules()
# Remove modules that are present on the disabled list
- self.extensions = [ext for ext in self.extensions
- if ext.name not in disabled_module_list]
+ extensions = [ext for ext in self.extensions
+ if ext.name not in disabled_module_list]
+ # move ctypes to the end, it depends on other modules
+ ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
+ if "_ctypes" in ext_map:
+ ctypes = extensions.pop(ext_map["_ctypes"])
+ extensions.append(ctypes)
+ self.extensions = extensions
# Fix up the autodetected modules, prefixing all the source files
# with Modules/ and adding Python's include directory to the path.