[Python-3000-checkins] r60044 - in python/branches/py3k: Doc/conf.py Doc/howto/curses.rst Doc/library/collections.rst Doc/library/itertools.rst Doc/library/msilib.rst Doc/library/queue.rst Doc/library/sched.rst Doc/library/smtplib.rst Doc/library/socket.rst Doc/tools/sphinx-build.py Doc/tools/sphinxext Doc/whatsnew/2.6.rst Lib/decimal.py Lib/pdb.py Lib/sched.py Lib/smtplib.py Lib/test/test_itertools.py Lib/test/test_queue.py Modules/_ctypes/libffi/src/x86/ffi_darwin.c Modules/_elementtree.c Modules/_struct.c Modules/itertoolsmodule.c Modules/main.c Modules/zipimport.c Parser/pgen.c Python/traceback.c setup.py
christian.heimes
python-3000-checkins at python.org
Fri Jan 18 10:56:23 CET 2008
Author: christian.heimes
Date: Fri Jan 18 10:56:22 2008
New Revision: 60044
Added:
python/branches/py3k/Doc/tools/sphinxext/
- copied from r60007, python/trunk/Doc/tools/sphinxext/
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Doc/conf.py
python/branches/py3k/Doc/howto/curses.rst
python/branches/py3k/Doc/library/collections.rst
python/branches/py3k/Doc/library/itertools.rst
python/branches/py3k/Doc/library/msilib.rst
python/branches/py3k/Doc/library/queue.rst
python/branches/py3k/Doc/library/sched.rst
python/branches/py3k/Doc/library/smtplib.rst
python/branches/py3k/Doc/library/socket.rst
python/branches/py3k/Doc/tools/sphinx-build.py
python/branches/py3k/Doc/whatsnew/2.6.rst
python/branches/py3k/Lib/decimal.py
python/branches/py3k/Lib/pdb.py
python/branches/py3k/Lib/sched.py
python/branches/py3k/Lib/smtplib.py
python/branches/py3k/Lib/test/test_itertools.py
python/branches/py3k/Lib/test/test_queue.py
python/branches/py3k/Modules/_ctypes/libffi/src/x86/ffi_darwin.c
python/branches/py3k/Modules/_elementtree.c
python/branches/py3k/Modules/_struct.c
python/branches/py3k/Modules/itertoolsmodule.c
python/branches/py3k/Modules/main.c
python/branches/py3k/Modules/zipimport.c
python/branches/py3k/Parser/pgen.c
python/branches/py3k/Python/traceback.c
python/branches/py3k/setup.py
Log:
Merged revisions 59985-60000,60002,60005-60007,60009-60042 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59987 | raymond.hettinger | 2008-01-15 21:52:42 +0100 (Tue, 15 Jan 2008) | 1 line
Refactor if/elif chain for clarity and speed. Remove dependency on subclasses having to implement _empty and _full.
........
r59988 | raymond.hettinger | 2008-01-15 22:22:47 +0100 (Tue, 15 Jan 2008) | 1 line
Fix-up half-written paragraph in the docs
........
r59989 | amaury.forgeotdarc | 2008-01-15 22:25:11 +0100 (Tue, 15 Jan 2008) | 3 lines
test_doctest fails since r59984.
Not sure if these are the correct values, but save_stdout has to be set before its usage...
........
r59992 | andrew.kuchling | 2008-01-16 01:32:03 +0100 (Wed, 16 Jan 2008) | 1 line
Docstring typos
........
r59993 | andrew.kuchling | 2008-01-16 04:17:25 +0100 (Wed, 16 Jan 2008) | 1 line
Add PEP 3141 section
........
r59998 | andrew.kuchling | 2008-01-16 14:01:51 +0100 (Wed, 16 Jan 2008) | 1 line
Markup fix
........
r59999 | georg.brandl | 2008-01-16 17:56:29 +0100 (Wed, 16 Jan 2008) | 2 lines
Fix MSDN library URL. (#1854)
........
r60006 | georg.brandl | 2008-01-16 21:27:56 +0100 (Wed, 16 Jan 2008) | 3 lines
Add Python-specific content to Doc dir. Update configuration file
to work with the newest Sphinx.
........
r60007 | georg.brandl | 2008-01-16 21:29:00 +0100 (Wed, 16 Jan 2008) | 2 lines
Doc build should work with 2.4 now.
........
r60009 | raymond.hettinger | 2008-01-17 00:38:16 +0100 (Thu, 17 Jan 2008) | 1 line
Minor wordsmithing.
........
r60010 | raymond.hettinger | 2008-01-17 00:40:45 +0100 (Thu, 17 Jan 2008) | 1 line
Add queues will alternative fetch orders (priority based and stack based).
........
r60011 | raymond.hettinger | 2008-01-17 00:49:35 +0100 (Thu, 17 Jan 2008) | 1 line
Add news entry.
........
r60013 | raymond.hettinger | 2008-01-17 04:02:14 +0100 (Thu, 17 Jan 2008) | 1 line
Make starmap() match its pure python definition and accept any itertable input (not just tuples).
........
r60015 | gregory.p.smith | 2008-01-17 08:43:20 +0100 (Thu, 17 Jan 2008) | 3 lines
Comply with RFC 3207.
Fixes issue 829951 - http://bugs.python.org/issue829951
........
r60018 | gregory.p.smith | 2008-01-17 09:03:17 +0100 (Thu, 17 Jan 2008) | 2 lines
entry for r60015
........
r60019 | raymond.hettinger | 2008-01-17 09:07:05 +0100 (Thu, 17 Jan 2008) | 1 line
Note versionadded.
........
r60020 | gregory.p.smith | 2008-01-17 09:35:49 +0100 (Thu, 17 Jan 2008) | 8 lines
Fixes (accepts patch) issue1339 - http://bugs.python.org/issue1339
- Factor out the duplication of EHLO/HELO in login() and sendmail() to
a new function, ehlo_or_helo_if_needed().
- Use ehlo_or_helo_if_needed() in starttls()
- Check for the starttls exception in starttls() in the same way as
login() checks for the auth extension.
Contributed by Bill Fenner.
........
r60021 | andrew.kuchling | 2008-01-17 13:00:15 +0100 (Thu, 17 Jan 2008) | 1 line
Revise 3141 section a bit; add some Windows items
........
r60022 | brett.cannon | 2008-01-17 19:45:10 +0100 (Thu, 17 Jan 2008) | 2 lines
Fix a function pointer declaration to silence the compiler.
........
r60024 | raymond.hettinger | 2008-01-17 20:31:38 +0100 (Thu, 17 Jan 2008) | 1 line
Issue #1861: Add read-only attribute listing upcoming events in the order they will be run.
........
r60025 | andrew.kuchling | 2008-01-17 20:49:24 +0100 (Thu, 17 Jan 2008) | 1 line
Correction from Jordan Lewis: halfdelay() uses tenths of a second, not milliseconds
........
r60026 | raymond.hettinger | 2008-01-17 23:27:49 +0100 (Thu, 17 Jan 2008) | 1 line
Add advice on choosing between scheduler and threading.Timer().
........
r60028 | christian.heimes | 2008-01-18 00:01:44 +0100 (Fri, 18 Jan 2008) | 2 lines
Updated new property syntax. An elaborate example for subclassing and the getter was missing.
Added comment about VS 2008 and PGO builds.
........
r60029 | raymond.hettinger | 2008-01-18 00:32:01 +0100 (Fri, 18 Jan 2008) | 1 line
Fix-up Timer() example.
........
r60030 | raymond.hettinger | 2008-01-18 00:56:56 +0100 (Fri, 18 Jan 2008) | 1 line
Fix markup
........
r60031 | raymond.hettinger | 2008-01-18 01:10:42 +0100 (Fri, 18 Jan 2008) | 1 line
clearcache() needs to remove the dict as well as clear it.
........
r60033 | andrew.kuchling | 2008-01-18 03:26:16 +0100 (Fri, 18 Jan 2008) | 1 line
Bump verson
........
r60034 | andrew.kuchling | 2008-01-18 03:42:52 +0100 (Fri, 18 Jan 2008) | 1 line
Typo fix
........
r60035 | christian.heimes | 2008-01-18 08:30:20 +0100 (Fri, 18 Jan 2008) | 3 lines
Coverity issue CID #197
var_decl: Declared variable "stm" without initializer
ninit_use_in_call: Using uninitialized value "stm" (field "stm".tm_zone uninitialized) in call to function "mktime"
........
r60036 | christian.heimes | 2008-01-18 08:45:30 +0100 (Fri, 18 Jan 2008) | 11 lines
Coverity issue CID #167
Event alloc_fn: Called allocation function "metacompile" [model]
Event var_assign: Assigned variable "gr" to storage returned from "metacompile"
gr = metacompile(n);
Event pass_arg: Variable "gr" not freed or pointed-to in function "maketables" [model]
g = maketables(gr);
translatelabels(g);
addfirstsets(g);
Event leaked_storage: Returned without freeing storage "gr"
return g;
........
r60038 | christian.heimes | 2008-01-18 09:04:57 +0100 (Fri, 18 Jan 2008) | 3 lines
Coverity issue CID #182
size_error: Allocating 1 bytes to pointer "children", which needs at least 4 bytes
........
r60041 | christian.heimes | 2008-01-18 09:47:59 +0100 (Fri, 18 Jan 2008) | 4 lines
Coverity issue CID #169
local_ptr_assign_local: Assigning address of stack variable "namebuf" to pointer "filename"
out_of_scope: Variable "namebuf" goes out of scope
use_invalid: Used "filename" pointing to out-of-scope variable "namebuf"
........
r60042 | christian.heimes | 2008-01-18 09:53:45 +0100 (Fri, 18 Jan 2008) | 2 lines
Coverity CID #168
leaked_storage: Returned without freeing storage "fp"
........
Modified: python/branches/py3k/Doc/conf.py
==============================================================================
--- python/branches/py3k/Doc/conf.py (original)
+++ python/branches/py3k/Doc/conf.py Fri Jan 18 10:56:22 2008
@@ -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 @@
'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 @@
# 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 @@
# 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 at 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']
Modified: python/branches/py3k/Doc/howto/curses.rst
==============================================================================
--- python/branches/py3k/Doc/howto/curses.rst (original)
+++ python/branches/py3k/Doc/howto/curses.rst Fri Jan 18 10:56:22 2008
@@ -3,7 +3,7 @@
**********************************
:Author: A.M. Kuchling, Eric S. Raymond
-:Release: 2.02
+:Release: 2.03
.. topic:: Abstract
@@ -367,8 +367,8 @@
``nodelay(1)``, :meth:`getch` for the window becomes non-blocking and returns
``curses.ERR`` (a value of -1) when no input is ready. There's also a
:func:`halfdelay` function, which can be used to (in effect) set a timer on each
-:meth:`getch`; if no input becomes available within the number of milliseconds
-specified as the argument to :func:`halfdelay`, curses raises an exception.
+:meth:`getch`; if no input becomes available within a specified
+delay (measured in tenths of a second), curses raises an exception.
The :meth:`getch` method returns an integer; if it's between 0 and 255, it
represents the ASCII code of the key pressed. Values greater than 255 are
Modified: python/branches/py3k/Doc/library/collections.rst
==============================================================================
--- python/branches/py3k/Doc/library/collections.rst (original)
+++ python/branches/py3k/Doc/library/collections.rst Fri Jan 18 10:56:22 2008
@@ -566,6 +566,9 @@
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::
Modified: python/branches/py3k/Doc/library/itertools.rst
==============================================================================
--- python/branches/py3k/Doc/library/itertools.rst (original)
+++ python/branches/py3k/Doc/library/itertools.rst Fri Jan 18 10:56:22 2008
@@ -319,16 +319,19 @@
.. 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)
Modified: python/branches/py3k/Doc/library/msilib.rst
==============================================================================
--- python/branches/py3k/Doc/library/msilib.rst (original)
+++ python/branches/py3k/Doc/library/msilib.rst Fri Jan 18 10:56:22 2008
@@ -146,7 +146,7 @@
.. seealso::
- `MSIOpenView <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msiopenview.asp>`_
+ `MSIDatabaseOpenView <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msidatabaseopenview.asp>`_
`MSIDatabaseCommit <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msidatabasecommit.asp>`_
`MSIGetSummaryInformation <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msigetsummaryinformation.asp>`_
Modified: python/branches/py3k/Doc/library/queue.rst
==============================================================================
--- python/branches/py3k/Doc/library/queue.rst (original)
+++ python/branches/py3k/Doc/library/queue.rst Fri Jan 18 10:56:22 2008
@@ -29,6 +29,7 @@
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 @@
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 @@
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
Modified: python/branches/py3k/Doc/library/sched.rst
==============================================================================
--- python/branches/py3k/Doc/library/sched.rst (original)
+++ python/branches/py3k/Doc/library/sched.rst Fri Jan 18 10:56:22 2008
@@ -41,13 +41,39 @@
From print_time 930343700.273
930343700.276
+In multi-threaded environments, the :class:`scheduler` class has limitations
+with respect to thread-safety, inability to insert a new task before
+the one currently pending in a running scheduler, and holding up the main
+thread until the event queue is empty. Instead, the preferred approach
+is to use the :class:`threading.Timer` class instead.
+
+Example::
+
+ >>> import time
+ >>> from threading import Timer
+ >>> def print_time():
+ ... print "From print_time", time.time()
+ ...
+ >>> def print_some_times():
+ ... print time.time()
+ ... Timer(5, print_time, ()).start()
+ ... Timer(10, print_time, ()).start()
+ ... time.sleep(11) # sleep while time-delay events execute
+ ... print time.time()
+ ...
+ >>> print_some_times()
+ 930343690.257
+ From print_time 930343695.274
+ From print_time 930343700.273
+ 930343701.301
+
.. _scheduler-objects:
Scheduler Objects
-----------------
-:class:`scheduler` instances have the following methods:
+:class:`scheduler` instances have the following methods and attributes:
.. method:: scheduler.enterabs(time, priority, action, argument)
@@ -98,3 +124,10 @@
the calling code is responsible for canceling events which are no longer
pertinent.
+.. attribute:: scheduler.queue
+
+ Read-only attribute returning a list of upcoming events in the order they
+ will be run. Each event is shown as a :term:`named tuple` with the
+ following fields: time, priority, action, argument.
+
+ .. versionadded:: 2.6
Modified: python/branches/py3k/Doc/library/smtplib.rst
==============================================================================
--- python/branches/py3k/Doc/library/smtplib.rst (original)
+++ python/branches/py3k/Doc/library/smtplib.rst Fri Jan 18 10:56:22 2008
@@ -184,6 +184,16 @@
necessary to call this method explicitly. It will be implicitly called by
:meth:`sendmail` when necessary.
+.. method:: SMTP.ehlo_or_helo_if_needed()
+
+ This method call :meth:`ehlo` and or :meth:`helo` if there has been no
+ previous ``EHLO`` or ``HELO`` command this session. It tries ESMTP ``EHLO``
+ first.
+
+ :exc:SMTPHeloError
+ The server didn't reply properly to the ``HELO`` greeting.
+
+ .. versionadded:: 2.6
.. method:: SMTP.has_extn(name)
@@ -230,6 +240,22 @@
If *keyfile* and *certfile* are provided, these are passed to the :mod:`socket`
module's :func:`ssl` function.
+ If there has been no previous ``EHLO`` or ``HELO`` command this session,
+ this method tries ESMTP ``EHLO`` first.
+
+ .. versionchanged:: 2.6
+
+ :exc:`SMTPHeloError`
+ The server didn't reply properly to the ``HELO`` greeting.
+
+ :exc:`SMTPException`
+ The server does not support the STARTTLS extension.
+
+ .. versionchanged:: 2.6
+
+ :exc:`RuntimeError`
+ SSL/TLS support is not available to your python interpreter.
+
.. method:: SMTP.sendmail(from_addr, to_addrs, msg[, mail_options, rcpt_options])
Modified: python/branches/py3k/Doc/library/socket.rst
==============================================================================
--- python/branches/py3k/Doc/library/socket.rst (original)
+++ python/branches/py3k/Doc/library/socket.rst Fri Jan 18 10:56:22 2008
@@ -562,7 +562,7 @@
: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.
Modified: python/branches/py3k/Doc/tools/sphinx-build.py
==============================================================================
--- python/branches/py3k/Doc/tools/sphinx-build.py (original)
+++ python/branches/py3k/Doc/tools/sphinx-build.py Fri Jan 18 10:56:22 2008
@@ -11,12 +11,13 @@
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
Modified: python/branches/py3k/Doc/whatsnew/2.6.rst
==============================================================================
--- python/branches/py3k/Doc/whatsnew/2.6.rst (original)
+++ python/branches/py3k/Doc/whatsnew/2.6.rst Fri Jan 18 10:56:22 2008
@@ -541,6 +541,90 @@
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 @@
.. 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 @@
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 @@
.. 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 @@
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.)
.. ======================================================================
Modified: python/branches/py3k/Lib/decimal.py
==============================================================================
--- python/branches/py3k/Lib/decimal.py (original)
+++ python/branches/py3k/Lib/decimal.py Fri Jan 18 10:56:22 2008
@@ -2982,7 +2982,7 @@
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 @@
"""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 @@
"""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.
Modified: python/branches/py3k/Lib/pdb.py
==============================================================================
--- python/branches/py3k/Lib/pdb.py (original)
+++ python/branches/py3k/Lib/pdb.py Fri Jan 18 10:56:22 2008
@@ -198,6 +198,8 @@
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
Modified: python/branches/py3k/Lib/sched.py
==============================================================================
--- python/branches/py3k/Lib/sched.py (original)
+++ python/branches/py3k/Lib/sched.py Fri Jan 18 10:56:22 2008
@@ -29,14 +29,17 @@
# XXX the global state of your particular time and delay functions.
import heapq
+from collections import namedtuple
__all__ = ["scheduler"]
+Event = namedtuple('Event', 'time, priority, action, argument')
+
class scheduler:
def __init__(self, timefunc, delayfunc):
"""Initialize a new instance, passing the time and delay
functions"""
- self.queue = []
+ self._queue = []
self.timefunc = timefunc
self.delayfunc = delayfunc
@@ -47,8 +50,8 @@
if necessary.
"""
- event = time, priority, action, argument
- heapq.heappush(self.queue, event)
+ event = Event(time, priority, action, argument)
+ heapq.heappush(self._queue, event)
return event # The ID
def enter(self, delay, priority, action, argument):
@@ -67,12 +70,12 @@
If the event is not in the queue, this raises RuntimeError.
"""
- self.queue.remove(event)
- heapq.heapify(self.queue)
+ self._queue.remove(event)
+ heapq.heapify(self._queue)
def empty(self):
"""Check whether the queue is empty."""
- return not self.queue
+ return not self._queue
def run(self):
"""Execute events until the queue is empty.
@@ -97,7 +100,7 @@
"""
# localize variable access to minimize overhead
# and to improve thread safety
- q = self.queue
+ q = self._queue
delayfunc = self.delayfunc
timefunc = self.timefunc
pop = heapq.heappop
@@ -115,3 +118,17 @@
delayfunc(0) # Let other threads run
else:
heapq.heappush(event)
+
+ @property
+ def queue(self):
+ """An ordered list of upcoming events.
+
+ Events are named tuples with fields for:
+ time, priority, action, arguments
+
+ """
+ # Use heapq to sort the queue rather than using 'sorted(self._queue)'.
+ # With heapq, two events scheduled at the same time will show in
+ # the actual order they would be retrieved.
+ events = self._queue[:]
+ return map(heapq.heappop, [events]*len(events))
Modified: python/branches/py3k/Lib/smtplib.py
==============================================================================
--- python/branches/py3k/Lib/smtplib.py (original)
+++ python/branches/py3k/Lib/smtplib.py Fri Jan 18 10:56:22 2008
@@ -495,6 +495,23 @@
# 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 @@
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 @@
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 @@
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
Modified: python/branches/py3k/Lib/test/test_itertools.py
==============================================================================
--- python/branches/py3k/Lib/test/test_itertools.py (original)
+++ python/branches/py3k/Lib/test/test_itertools.py Fri Jan 18 10:56:22 2008
@@ -300,7 +300,8 @@
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)]))
Modified: python/branches/py3k/Lib/test/test_queue.py
==============================================================================
--- python/branches/py3k/Lib/test/test_queue.py (original)
+++ python/branches/py3k/Lib/test/test_queue.py Fri Jan 18 10:56:22 2008
@@ -184,28 +184,35 @@
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 @@
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 @@
raise TestFailed("Did not detect task count going negative")
def test():
- q = Queue.Queue()
- QueueTaskDoneTest(q)
- QueueJoinTest(q)
- QueueJoinTest(q)
- QueueTaskDoneTest(q)
-
- q = Queue.Queue(QUEUE_SIZE)
- # Do it a couple of times on the same queue
- SimpleQueueTest(q)
- SimpleQueueTest(q)
- if verbose:
- print("Simple Queue tests seemed to work")
+ 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 = FailingQueue(QUEUE_SIZE)
FailingQueueTest(q)
FailingQueueTest(q)
Modified: python/branches/py3k/Modules/_ctypes/libffi/src/x86/ffi_darwin.c
==============================================================================
--- python/branches/py3k/Modules/_ctypes/libffi/src/x86/ffi_darwin.c (original)
+++ python/branches/py3k/Modules/_ctypes/libffi/src/x86/ffi_darwin.c Fri Jan 18 10:56:22 2008
@@ -217,7 +217,7 @@
#endif /* X86_WIN32 */
void ffi_call(/*@dependent@*/ ffi_cif *cif,
- void (*fn)(),
+ void (*fn)(void),
/*@out@*/ void *rvalue,
/*@dependent@*/ void **avalue)
{
Modified: python/branches/py3k/Modules/_elementtree.c
==============================================================================
--- python/branches/py3k/Modules/_elementtree.c (original)
+++ python/branches/py3k/Modules/_elementtree.c Fri Jan 18 10:56:22 2008
@@ -348,7 +348,17 @@
if (size > self->extra->allocated) {
/* use Python 2.4's list growth strategy */
size = (size >> 3) + (size < 9 ? 3 : 6) + size;
+ /* Coverity CID #182 size_error: Allocating 1 bytes to pointer "children"
+ * which needs at least 4 bytes.
+ * Although it's a false alarm always assume at least one child to
+ * be safe.
+ */
+ size = size ? size : 1;
if (self->extra->children != self->extra->_children) {
+ /* Coverity CID #182 size_error: Allocating 1 bytes to pointer
+ * "children", which needs at least 4 bytes. Although it's a
+ * false alarm always assume at least one child to be safe.
+ */
children = PyObject_Realloc(self->extra->children,
size * sizeof(PyObject*));
if (!children)
Modified: python/branches/py3k/Modules/_struct.c
==============================================================================
--- python/branches/py3k/Modules/_struct.c (original)
+++ python/branches/py3k/Modules/_struct.c Fri Jan 18 10:56:22 2008
@@ -1918,8 +1918,7 @@
static PyObject *
clearcache(PyObject *self)
{
- if (cache != NULL)
- PyDict_Clear(cache);
+ Py_CLEAR(cache);
Py_RETURN_NONE;
}
Modified: python/branches/py3k/Modules/itertoolsmodule.c
==============================================================================
--- python/branches/py3k/Modules/itertoolsmodule.c (original)
+++ python/branches/py3k/Modules/itertoolsmodule.c Fri Jan 18 10:56:22 2008
@@ -1356,10 +1356,11 @@
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);
Modified: python/branches/py3k/Modules/main.c
==============================================================================
--- python/branches/py3k/Modules/main.c (original)
+++ python/branches/py3k/Modules/main.c Fri Jan 18 10:56:22 2008
@@ -533,6 +533,7 @@
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;
}
}
Modified: python/branches/py3k/Modules/zipimport.c
==============================================================================
--- python/branches/py3k/Modules/zipimport.c (original)
+++ python/branches/py3k/Modules/zipimport.c Fri Jan 18 10:56:22 2008
@@ -1000,6 +1000,8 @@
{
struct tm stm;
+ memset((void *) &stm, '\0', sizeof(stm));
+
stm.tm_sec = (dostime & 0x1f) * 2;
stm.tm_min = (dostime >> 5) & 0x3f;
stm.tm_hour = (dostime >> 11) & 0x1f;
Modified: python/branches/py3k/Parser/pgen.c
==============================================================================
--- python/branches/py3k/Parser/pgen.c (original)
+++ python/branches/py3k/Parser/pgen.c Fri Jan 18 10:56:22 2008
@@ -667,6 +667,7 @@
g = maketables(gr);
translatelabels(g);
addfirstsets(g);
+ PyObject_FREE(gr);
return g;
}
Modified: python/branches/py3k/Python/traceback.c
==============================================================================
--- python/branches/py3k/Python/traceback.c (original)
+++ python/branches/py3k/Python/traceback.c Fri Jan 18 10:56:22 2008
@@ -135,6 +135,8 @@
FILE *xfp;
char linebuf[2000];
int i;
+ char namebuf[MAXPATHLEN+1];
+
if (filename == NULL || name == NULL)
return -1;
/* This is needed by Emacs' compile command */
@@ -153,7 +155,6 @@
Py_ssize_t _npath = PyList_Size(path);
int npath = Py_SAFE_DOWNCAST(_npath, Py_ssize_t, int);
size_t taillen = strlen(tail);
- char namebuf[MAXPATHLEN+1];
for (i = 0; i < npath; i++) {
PyObject *v = PyList_GetItem(path, i);
if (v == NULL) {
Modified: python/branches/py3k/setup.py
==============================================================================
--- python/branches/py3k/setup.py (original)
+++ python/branches/py3k/setup.py Fri Jan 18 10:56:22 2008
@@ -101,8 +101,14 @@
missing = self.detect_modules()
# Remove modules that are present on the disabled list
- self.extensions = [ext for ext in self.extensions
- if ext.name not in disabled_module_list]
+ extensions = [ext for ext in self.extensions
+ if ext.name not in disabled_module_list]
+ # move ctypes to the end, it depends on other modules
+ ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
+ if "_ctypes" in ext_map:
+ ctypes = extensions.pop(ext_map["_ctypes"])
+ extensions.append(ctypes)
+ self.extensions = extensions
# Fix up the autodetected modules, prefixing all the source files
# with Modules/ and adding Python's include directory to the path.
More information about the Python-3000-checkins
mailing list