[Python-checkins] r66879 - in python/branches/tlee-ast-optimize: Doc/c-api/init.rst Doc/conf.py Doc/contents.rst Doc/library/functions.rst Doc/library/sqlite3.rst Doc/library/subprocess.rst Doc/library/thread.rst Doc/reference/simple_stmts.rst Doc/tools/sphinxext/indexcontent.html Doc/whatsnew/2.3.rst Doc/whatsnew/2.4.rst Doc/whatsnew/2.5.rst Doc/whatsnew/2.6.rst Doc/whatsnew/index.rst Lib/test/test_bisect.py Lib/test/test_poplib.py Makefile.pre.in Misc/NEWS Modules/_bisectmodule.c Modules/posixmodule.c

thomas.lee python-checkins at python.org
Sun Oct 12 14:40:03 CEST 2008


Author: thomas.lee
Date: Sun Oct 12 14:40:01 2008
New Revision: 66879

Log:
Merged revisions 66844-66878 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r66852 | andrew.kuchling | 2008-10-09 00:21:27 +1100 (Thu, 09 Oct 2008) | 1 line
  
  Note how bytes alias is expected to be used
........
  r66854 | georg.brandl | 2008-10-09 04:20:20 +1100 (Thu, 09 Oct 2008) | 2 lines
  
  #4059: patch up some sqlite docs.
........
  r66855 | georg.brandl | 2008-10-09 04:30:55 +1100 (Thu, 09 Oct 2008) | 2 lines
  
  #4058: fix some whatsnew markup.
........
  r66856 | georg.brandl | 2008-10-09 05:47:17 +1100 (Thu, 09 Oct 2008) | 3 lines
  
  #3935: properly support list subclasses in the C impl. of bisect.
  Patch reviewed by Raymond.
........
  r66857 | georg.brandl | 2008-10-09 05:57:13 +1100 (Thu, 09 Oct 2008) | 2 lines
  
  Make all whatsnew docs accessible.
........
  r66861 | benjamin.peterson | 2008-10-09 08:11:33 +1100 (Thu, 09 Oct 2008) | 1 line
  
  quiet sphinx warnings
........
  r66862 | hirokazu.yamamoto | 2008-10-09 21:00:30 +1100 (Thu, 09 Oct 2008) | 3 lines
  
  On windows, os.chdir given unicode was not working if GetCurrentDirectoryW
  returned a path longer than MAX_PATH. (But It's doubtful this code path is
  really executed because I cannot move to such directory on win2k)
........
  r66863 | hirokazu.yamamoto | 2008-10-09 21:11:21 +1100 (Thu, 09 Oct 2008) | 1 line
  
  r66862 contained memory leak.
........
  r66866 | benjamin.peterson | 2008-10-10 07:54:43 +1100 (Fri, 10 Oct 2008) | 1 line
  
  update paragraph about __future__ for 2.6
........
  r66868 | matthias.klose | 2008-10-10 18:24:20 +1100 (Fri, 10 Oct 2008) | 2 lines
  
  - Makefile.pre.in(PROFILE_TASK): search files in srcdir
........
  r66870 | armin.rigo | 2008-10-10 19:40:44 +1100 (Fri, 10 Oct 2008) | 2 lines
  
  Typo: "ThreadError" is the name in the C source.
........
  r66871 | benjamin.peterson | 2008-10-11 07:38:49 +1100 (Sat, 11 Oct 2008) | 1 line
  
  fix a small typo
........
  r66872 | benjamin.peterson | 2008-10-11 07:51:37 +1100 (Sat, 11 Oct 2008) | 1 line
  
  talk about how you can unzip with zip
........
  r66874 | benjamin.peterson | 2008-10-11 09:23:41 +1100 (Sat, 11 Oct 2008) | 1 line
  
  PyGILState_Acquire -> PyGILState_Ensure
........
  r66878 | benjamin.peterson | 2008-10-12 04:25:36 +1100 (Sun, 12 Oct 2008) | 4 lines
  
  give poplib a real test suite
  
  #4088 from Giampaolo Rodola'x
........


Added:
   python/branches/tlee-ast-optimize/Doc/whatsnew/index.rst
      - copied unchanged from r66878, /python/trunk/Doc/whatsnew/index.rst
Modified:
   python/branches/tlee-ast-optimize/   (props changed)
   python/branches/tlee-ast-optimize/Doc/c-api/init.rst
   python/branches/tlee-ast-optimize/Doc/conf.py
   python/branches/tlee-ast-optimize/Doc/contents.rst
   python/branches/tlee-ast-optimize/Doc/library/functions.rst
   python/branches/tlee-ast-optimize/Doc/library/sqlite3.rst
   python/branches/tlee-ast-optimize/Doc/library/subprocess.rst
   python/branches/tlee-ast-optimize/Doc/library/thread.rst
   python/branches/tlee-ast-optimize/Doc/reference/simple_stmts.rst
   python/branches/tlee-ast-optimize/Doc/tools/sphinxext/indexcontent.html
   python/branches/tlee-ast-optimize/Doc/whatsnew/2.3.rst
   python/branches/tlee-ast-optimize/Doc/whatsnew/2.4.rst
   python/branches/tlee-ast-optimize/Doc/whatsnew/2.5.rst
   python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst
   python/branches/tlee-ast-optimize/Lib/test/test_bisect.py
   python/branches/tlee-ast-optimize/Lib/test/test_poplib.py
   python/branches/tlee-ast-optimize/Makefile.pre.in
   python/branches/tlee-ast-optimize/Misc/NEWS
   python/branches/tlee-ast-optimize/Modules/_bisectmodule.c
   python/branches/tlee-ast-optimize/Modules/posixmodule.c

Modified: python/branches/tlee-ast-optimize/Doc/c-api/init.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/c-api/init.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/c-api/init.rst	Sun Oct 12 14:40:01 2008
@@ -755,11 +755,11 @@
    :cmacro:`Py_END_ALLOW_THREADS` macros is acceptable.
 
    The return value is an opaque "handle" to the thread state when
-   :cfunc:`PyGILState_Acquire` was called, and must be passed to
+   :cfunc:`PyGILState_Ensure` was called, and must be passed to
    :cfunc:`PyGILState_Release` to ensure Python is left in the same state. Even
    though recursive calls are allowed, these handles *cannot* be shared - each
-   unique call to :cfunc:`PyGILState_Ensure` must save the handle for its call to
-   :cfunc:`PyGILState_Release`.
+   unique call to :cfunc:`PyGILState_Ensure` must save the handle for its call
+   to :cfunc:`PyGILState_Release`.
 
    When the function returns, the current thread will hold the GIL. Failure is a
    fatal error.

Modified: python/branches/tlee-ast-optimize/Doc/conf.py
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/conf.py	(original)
+++ python/branches/tlee-ast-optimize/Doc/conf.py	Sun Oct 12 14:40:01 2008
@@ -41,13 +41,6 @@
 
 # List of files that shouldn't be included in the build.
 unused_docs = [
-    'whatsnew/2.0',
-    'whatsnew/2.1',
-    'whatsnew/2.2',
-    'whatsnew/2.3',
-    'whatsnew/2.4',
-    'whatsnew/2.5',
-    'whatsnew/2.6',
     'maclib/scrap',
     'library/xmllib',
     'library/xml.etree',

Modified: python/branches/tlee-ast-optimize/Doc/contents.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/contents.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/contents.rst	Sun Oct 12 14:40:01 2008
@@ -4,7 +4,7 @@
 
 .. toctree::
 
-   whatsnew/2.7.rst
+   whatsnew/index.rst
    tutorial/index.rst
    using/index.rst
    reference/index.rst

Modified: python/branches/tlee-ast-optimize/Doc/library/functions.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/functions.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/functions.rst	Sun Oct 12 14:40:01 2008
@@ -1387,6 +1387,18 @@
    makes possible an idiom for clustering a data series into n-length groups
    using ``zip(*[iter(s)]*n)``.
 
+   :func:`zip` in conjunction with the ``*`` operator can be used to unzip a
+   list::
+
+      >>> x = [1, 2, 3]
+      >>> y = [4, 5, 6]
+      >>> zipped = zip(x, y)
+      >>> zipped
+      [(1, 4), (2, 5), (3, 6)]
+      >>> x2, y2 = zip(*zipped)
+      >>> x == x2, y == y2
+      True
+
    .. versionadded:: 2.0
 
    .. versionchanged:: 2.4

Modified: python/branches/tlee-ast-optimize/Doc/library/sqlite3.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/sqlite3.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/sqlite3.rst	Sun Oct 12 14:40:01 2008
@@ -27,7 +27,7 @@
 You can also supply the special name ``:memory:`` to create a database in RAM.
 
 Once you have a :class:`Connection`, you can create a :class:`Cursor`  object
-and call its :meth:`execute` method to perform SQL commands::
+and call its :meth:`~Cursor.execute` method to perform SQL commands::
 
    c = conn.cursor()
 
@@ -52,7 +52,7 @@
 
 Instead, use the DB-API's parameter substitution.  Put ``?`` as a placeholder
 wherever you want to use a value, and then provide a tuple of values as the
-second argument to the cursor's :meth:`execute` method.  (Other database modules
+second argument to the cursor's :meth:`~Cursor.execute` method.  (Other database modules
 may use a different placeholder, such as ``%s`` or ``:1``.) For example::
 
    # Never do this -- insecure!
@@ -71,8 +71,8 @@
        c.execute('insert into stocks values (?,?,?,?,?)', t)
 
 To retrieve data after executing a SELECT statement, you can either treat the
-cursor as an :term:`iterator`, call the cursor's :meth:`fetchone` method to
-retrieve a single matching row, or call :meth:`fetchall` to get a list of the
+cursor as an :term:`iterator`, call the cursor's :meth:`~Cursor.fetchone` method to
+retrieve a single matching row, or call :meth:`~Cursor.fetchall` to get a list of the
 matching rows.
 
 This example uses the iterator form::
@@ -130,7 +130,7 @@
    returns.  It will look for a string formed [mytype] in there, and then decide
    that 'mytype' is the type of the column. It will try to find an entry of
    'mytype' in the converters dictionary and then use the converter function found
-   there to return the value. The column name found in :attr:`cursor.description`
+   there to return the value. The column name found in :attr:`Cursor.description`
    is only the first word of the column name, i.  e. if you use something like
    ``'as "x [datetime]"'`` in your SQL, then we will parse out everything until the
    first blank for the column name: the column name would simply be "x".
@@ -217,11 +217,13 @@
 Connection Objects
 ------------------
 
-A :class:`Connection` instance has the following attributes and methods:
+.. class:: Connection
+
+   A SQLite database connection has the following attributes and methods:
 
 .. attribute:: Connection.isolation_level
 
-   Get or set the current isolation level. None for autocommit mode or one of
+   Get or set the current isolation level. :const:`None` for autocommit mode or one of
    "DEFERRED", "IMMEDIATE" or "EXLUSIVE". See section
    :ref:`sqlite3-controlling-transactions` for a more detailed explanation.
 
@@ -236,7 +238,7 @@
 .. method:: Connection.commit()
 
    This method commits the current transaction. If you don't call this method,
-   anything you did since the last call to commit() is not visible from from
+   anything you did since the last call to ``commit()`` is not visible from from
    other database connections. If you wonder why you don't see the data you've
    written to the database, please check you didn't forget to call this method.
 
@@ -386,9 +388,9 @@
 
 .. attribute:: Connection.text_factory
 
-   Using this attribute you can control what objects are returned for the TEXT data
-   type. By default, this attribute is set to :class:`unicode` and the
-   :mod:`sqlite3` module will return Unicode objects for TEXT. If you want to
+   Using this attribute you can control what objects are returned for the ``TEXT``
+   data type. By default, this attribute is set to :class:`unicode` and the
+   :mod:`sqlite3` module will return Unicode objects for ``TEXT``. If you want to
    return bytestrings instead, you can set it to :class:`str`.
 
    For efficiency reasons, there's also a way to return Unicode objects only for
@@ -435,8 +437,9 @@
 Cursor Objects
 --------------
 
-A :class:`Cursor` instance has the following attributes and methods:
+.. class:: Cursor
 
+   A SQLite database cursor has the following attributes and methods:
 
 .. method:: Cursor.execute(sql, [parameters])
 
@@ -475,7 +478,7 @@
 .. method:: Cursor.executescript(sql_script)
 
    This is a nonstandard convenience method for executing multiple SQL statements
-   at once. It issues a COMMIT statement first, then executes the SQL script it
+   at once. It issues a ``COMMIT`` statement first, then executes the SQL script it
    gets as a parameter.
 
    *sql_script* can be a bytestring or a Unicode string.
@@ -488,7 +491,7 @@
 .. method:: Cursor.fetchone() 
           
    Fetches the next row of a query result set, returning a single sequence,
-   or ``None`` when no more data is available.
+   or :const:`None` when no more data is available.
 
 
 .. method:: Cursor.fetchmany([size=cursor.arraysize])
@@ -527,8 +530,8 @@
    into :attr:`rowcount`.
 
    As required by the Python DB API Spec, the :attr:`rowcount` attribute "is -1 in
-   case no executeXX() has been performed on the cursor or the rowcount of the last
-   operation is not determinable by the interface".
+   case no ``executeXX()`` has been performed on the cursor or the rowcount of the
+   last operation is not determinable by the interface".
 
    This includes ``SELECT`` statements because we cannot determine the number of
    rows a query produced until all rows were fetched.
@@ -540,6 +543,81 @@
    method. For operations other than ``INSERT`` or when :meth:`executemany` is
    called, :attr:`lastrowid` is set to :const:`None`.
 
+.. attribute:: Cursor.description
+
+   This read-only attribute provides the column names of the last query. To
+   remain compatible with the Python DB API, it returns a 7-tuple for each
+   column where the last six items of each tuple are :const:`None`. 
+   
+   It is set for ``SELECT`` statements without any matching rows as well.
+
+.. _sqlite3-row-objects:
+
+Row Objects
+-----------
+
+.. class:: Row
+
+   A :class:`Row` instance serves as a highly optimized
+   :attr:`~Connection.row_factory` for :class:`Connection` objects. 
+   It tries to mimic a tuple in most of its features.
+
+   It supports mapping access by column name and index, iteration,
+   representation, equality testing and :func:`len`.
+
+   If two :class:`Row` objects have exactly the same columns and their
+   members are equal, they compare equal.
+   
+   .. versionchanged:: 2.6
+      Added iteration and equality (hashability).
+
+   .. method:: keys
+
+      This method returns a tuple of column names. Immediately after a query,
+      it is the first member of each tuple in :attr:`Cursor.description`.
+
+      .. versionadded:: 2.6
+
+Let's assume we initialize a table as in the example given above::
+
+    conn = sqlite3.connect(":memory:")
+    c = conn.cursor()
+    c.execute('''create table stocks
+    (date text, trans text, symbol text,
+     qty real, price real)''')
+    c.execute("""insert into stocks
+              values ('2006-01-05','BUY','RHAT',100,35.14)""")
+    conn.commit()
+    c.close()
+
+Now we plug :class:`Row` in::
+
+    >>> conn.row_factory = sqlite3.Row
+    >>> c = conn.cursor()
+    >>> c.execute('select * from stocks')
+    <sqlite3.Cursor object at 0x7f4e7dd8fa80>
+    >>> r = c.fetchone()
+    >>> type(r)
+    <type 'sqlite3.Row'>
+    >>> r
+    (u'2006-01-05', u'BUY', u'RHAT', 100.0, 35.140000000000001)
+    >>> len(r)
+    5
+    >>> r[2]
+    u'RHAT'
+    >>> r.keys()
+    ['date', 'trans', 'symbol', 'qty', 'price']
+    >>> r['qty']
+    100.0
+    >>> for member in r: print member
+    ...
+    2006-01-05
+    BUY
+    RHAT
+    100.0
+    35.14
+
+
 .. _sqlite3-types:
 
 SQLite and Python types
@@ -549,43 +627,46 @@
 Introduction
 ^^^^^^^^^^^^
 
-SQLite natively supports the following types: NULL, INTEGER, REAL, TEXT, BLOB.
+SQLite natively supports the following types: ``NULL``, ``INTEGER``,
+``REAL``, ``TEXT``, ``BLOB``.
 
 The following Python types can thus be sent to SQLite without any problem:
 
-+------------------------+-------------+
-| Python type            | SQLite type |
-+========================+=============+
-| ``None``               | NULL        |
-+------------------------+-------------+
-| ``int``                | INTEGER     |
-+------------------------+-------------+
-| ``long``               | INTEGER     |
-+------------------------+-------------+
-| ``float``              | REAL        |
-+------------------------+-------------+
-| ``str (UTF8-encoded)`` | TEXT        |
-+------------------------+-------------+
-| ``unicode``            | TEXT        |
-+------------------------+-------------+
-| ``buffer``             | BLOB        |
-+------------------------+-------------+
++-----------------------------+-------------+
+| Python type                 | SQLite type |
++=============================+=============+
+| :const:`None`               | ``NULL``    |
++-----------------------------+-------------+
+| :class:`int`                | ``INTEGER`` |
++-----------------------------+-------------+
+| :class:`long`               | ``INTEGER`` |
++-----------------------------+-------------+
+| :class:`float`              | ``REAL``    |
++-----------------------------+-------------+
+| :class:`str` (UTF8-encoded) | ``TEXT``    |
++-----------------------------+-------------+
+| :class:`unicode`            | ``TEXT``    |
++-----------------------------+-------------+
+| :class:`buffer`             | ``BLOB``    |
++-----------------------------+-------------+
 
 This is how SQLite types are converted to Python types by default:
 
-+-------------+---------------------------------------------+
-| SQLite type | Python type                                 |
-+=============+=============================================+
-| ``NULL``    | None                                        |
-+-------------+---------------------------------------------+
-| ``INTEGER`` | int or long, depending on size              |
-+-------------+---------------------------------------------+
-| ``REAL``    | float                                       |
-+-------------+---------------------------------------------+
-| ``TEXT``    | depends on text_factory, unicode by default |
-+-------------+---------------------------------------------+
-| ``BLOB``    | buffer                                      |
-+-------------+---------------------------------------------+
++-------------+----------------------------------------------+
+| SQLite type | Python type                                  |
++=============+==============================================+
+| ``NULL``    | :const:`None`                                |
++-------------+----------------------------------------------+
+| ``INTEGER`` | :class:`int` or :class:`long`,               |
+|             | depending on size                            |
++-------------+----------------------------------------------+
+| ``REAL``    | :class:`float`                               |
++-------------+----------------------------------------------+
+| ``TEXT``    | depends on :attr:`~Connection.text_factory`, |
+|             | :class:`unicode` by default                  |
++-------------+----------------------------------------------+
+| ``BLOB``    | :class:`buffer`                              |
++-------------+----------------------------------------------+
 
 The type system of the :mod:`sqlite3` module is extensible in two ways: you can
 store additional Python types in a SQLite database via object adaptation, and
@@ -713,9 +794,10 @@
 ------------------------
 
 By default, the :mod:`sqlite3` module opens transactions implicitly before a
-Data Modification Language (DML)  statement (i.e. INSERT/UPDATE/DELETE/REPLACE),
-and commits transactions implicitly before a non-DML, non-query statement (i. e.
-anything other than SELECT/INSERT/UPDATE/DELETE/REPLACE).
+Data Modification Language (DML)  statement (i.e. 
+``INSERT``/``UPDATE``/``DELETE``/``REPLACE``), and commits transactions
+implicitly before a non-DML, non-query statement (i. e.
+anything other than ``SELECT`` or the aforementioned).
 
 So if you are within a transaction and issue a command like ``CREATE TABLE
 ...``, ``VACUUM``, ``PRAGMA``, the :mod:`sqlite3` module will commit implicitly
@@ -724,7 +806,7 @@
 is that pysqlite needs to keep track of the transaction state (if a transaction
 is active or not).
 
-You can control which kind of "BEGIN" statements pysqlite implicitly executes
+You can control which kind of ``BEGIN`` statements pysqlite implicitly executes
 (or none at all) via the *isolation_level* parameter to the :func:`connect`
 call, or via the :attr:`isolation_level` property of connections.
 
@@ -748,7 +830,7 @@
 be written more concisely because you don't have to create the (often
 superfluous) :class:`Cursor` objects explicitly. Instead, the :class:`Cursor`
 objects are created implicitly and these shortcut methods return the cursor
-objects. This way, you can execute a SELECT statement and iterate over it
+objects. This way, you can execute a ``SELECT`` statement and iterate over it
 directly using only a single call on the :class:`Connection` object.
 
 .. literalinclude:: ../includes/sqlite3/shortcut_methods.py

Modified: python/branches/tlee-ast-optimize/Doc/library/subprocess.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/subprocess.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/subprocess.rst	Sun Oct 12 14:40:01 2008
@@ -318,8 +318,8 @@
    output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0]
 
 
-Replacing shell pipe line
-^^^^^^^^^^^^^^^^^^^^^^^^^
+Replacing shell pipeline
+^^^^^^^^^^^^^^^^^^^^^^^^
 
 ::
 

Modified: python/branches/tlee-ast-optimize/Doc/library/thread.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/thread.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/thread.rst	Sun Oct 12 14:40:01 2008
@@ -99,7 +99,7 @@
    *size* argument specifies the stack size to be used for subsequently created
    threads, and must be 0 (use platform or configured default) or a positive
    integer value of at least 32,768 (32kB). If changing the thread stack size is
-   unsupported, a :exc:`ThreadError` is raised.  If the specified stack size is
+   unsupported, the :exc:`error` exception is raised.  If the specified stack size is
    invalid, a :exc:`ValueError` is raised and the stack size is unmodified.  32kB
    is currently the minimum supported stack size value to guarantee sufficient
    stack space for the interpreter itself.  Note that some platforms may have

Modified: python/branches/tlee-ast-optimize/Doc/reference/simple_stmts.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/reference/simple_stmts.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/reference/simple_stmts.rst	Sun Oct 12 14:40:01 2008
@@ -788,10 +788,11 @@
 * blank lines, and
 * other future statements.
 
-The features recognized by Python 2.5 are ``absolute_import``, ``division``,
-``generators``, ``nested_scopes`` and ``with_statement``.  ``generators`` and
-``nested_scopes``  are redundant in Python version 2.3 and above because they
-are always enabled.
+The features recognized by Python 2.6 are ``unicode_literals``,
+``print_function``, ``absolute_import``, ``division``, ``generators``,
+``nested_scopes`` and ``with_statement``.  ``generators``, ``with_statement``,
+``nested_scopes`` are redundant in Python version 2.6 and above because they are
+always enabled.
 
 A future statement is recognized and treated specially at compile time: Changes
 to the semantics of core constructs are often implemented by generating

Modified: python/branches/tlee-ast-optimize/Doc/tools/sphinxext/indexcontent.html
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/tools/sphinxext/indexcontent.html	(original)
+++ python/branches/tlee-ast-optimize/Doc/tools/sphinxext/indexcontent.html	Sun Oct 12 14:40:01 2008
@@ -4,7 +4,7 @@
   <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>
+         <span class="linkdescr">or <a href="{{ pathto("whatsnew/index") }}">all "What's new" documents</a> since 2.0</span></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/>

Modified: python/branches/tlee-ast-optimize/Doc/whatsnew/2.3.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/whatsnew/2.3.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/whatsnew/2.3.rst	Sun Oct 12 14:40:01 2008
@@ -2062,7 +2062,7 @@
 .. ======================================================================
 
 
-.. _acks:
+.. _23acks:
 
 Acknowledgements
 ================

Modified: python/branches/tlee-ast-optimize/Doc/whatsnew/2.4.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/whatsnew/2.4.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/whatsnew/2.4.rst	Sun Oct 12 14:40:01 2008
@@ -1551,7 +1551,7 @@
 .. ======================================================================
 
 
-.. _acks:
+.. _24acks:
 
 Acknowledgements
 ================

Modified: python/branches/tlee-ast-optimize/Doc/whatsnew/2.5.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/whatsnew/2.5.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/whatsnew/2.5.rst	Sun Oct 12 14:40:01 2008
@@ -16,9 +16,9 @@
 The changes in Python 2.5 are an interesting mix of language and library
 improvements. The library enhancements will be more important to Python's user
 community, I think, because several widely-useful packages were added.  New
-modules include ElementTree for XML processing (section :ref:`module-etree`),
-the SQLite database module (section :ref:`module-sqlite`), and the :mod:`ctypes`
-module for calling C functions (section :ref:`module-ctypes`).
+modules include ElementTree for XML processing (:mod:`xml.etree`),
+the SQLite database module (:mod:`sqlite`), and the :mod:`ctypes`
+module for calling C functions.
 
 The language changes are of middling significance.  Some pleasant new features
 were added, but most of them aren't features that you'll use every day.
@@ -736,7 +736,7 @@
                # return False
 
 
-.. _module-contextlib:
+.. _contextlibmod:
 
 The contextlib module
 ---------------------
@@ -1109,7 +1109,7 @@
 .. ======================================================================
 
 
-.. _interactive:
+.. _25interactive:
 
 Interactive Interpreter Changes
 -------------------------------
@@ -1211,7 +1211,7 @@
 .. ======================================================================
 
 
-.. _modules:
+.. _25modules:
 
 New, Improved, and Removed Modules
 ==================================
@@ -1273,7 +1273,7 @@
   (Contributed by Raymond Hettinger.)
 
 * New module: The :mod:`contextlib` module contains helper functions for use
-  with the new ':keyword:`with`' statement.  See section :ref:`module-contextlib`
+  with the new ':keyword:`with`' statement.  See section :ref:`contextlibmod`
   for more about this module.
 
 * New module: The :mod:`cProfile` module is a C implementation of  the existing
@@ -2272,8 +2272,6 @@
 .. ======================================================================
 
 
-.. _acks:
-
 Acknowledgements
 ================
 

Modified: python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst	Sun Oct 12 14:40:01 2008
@@ -662,33 +662,33 @@
     from multiprocessing import Pool, Manager
 
     def factorial(N, dictionary):
-	"Compute a factorial."
-	# Calculate the result
-	fact = 1L
-	for i in range(1, N+1):
-	    fact = fact * i
+        "Compute a factorial."
+        # Calculate the result
+        fact = 1L
+        for i in range(1, N+1):
+            fact = fact * i
 
         # Store result in dictionary
-	dictionary[N] = fact
+        dictionary[N] = fact
 
     if __name__ == '__main__':
-	p = Pool(5)
-	mgr = Manager()
-	d = mgr.dict()         # Create shared dictionary
-
-	# Run tasks using the pool
-	for N in range(1, 1000, 10):
-	    p.apply_async(factorial, (N, d))
-
-	# Mark pool as closed -- no more tasks can be added.
-	p.close()
-
-	# Wait for tasks to exit
-	p.join()
-
-	# Output results
-	for k, v in sorted(d.items()):
-	    print k, v
+        p = Pool(5)
+        mgr = Manager()
+        d = mgr.dict()         # Create shared dictionary
+
+        # Run tasks using the pool
+        for N in range(1, 1000, 10):
+            p.apply_async(factorial, (N, d))
+
+    # Mark pool as closed -- no more tasks can be added.
+    p.close()
+
+    # Wait for tasks to exit
+    p.join()
+
+    # Output results
+    for k, v in sorted(d.items()):
+        print k, v
 
 This will produce the output::
 
@@ -723,32 +723,33 @@
 treats the string as a template and takes the arguments to be formatted.
 The formatting template uses curly brackets (`{`, `}`) as special characters::
 
-     # Substitute positional argument 0 into the string.
-     "User ID: {0}".format("root") -> "User ID: root"
-
-     # Use the named keyword arguments
-     'User ID: {uid}   Last seen: {last_login}'.format(
-            uid='root',
-            last_login = '5 Mar 2008 07:20') ->
-       'User ID: root   Last seen: 5 Mar 2008 07:20'
+     >>> # Substitute positional argument 0 into the string.
+     >>> "User ID: {0}".format("root")
+     'User ID: root'
+     >>> # Use the named keyword arguments
+     >>> "User ID: {uid}   Last seen: {last_login}".format(
+     ...    uid="root",
+     ...    last_login = "5 Mar 2008 07:20")
+     'User ID: root   Last seen: 5 Mar 2008 07:20'
 
 Curly brackets can be escaped by doubling them::
 
-     format("Empty dict: {{}}") -> "Empty dict: {}"
+     >>> format("Empty dict: {{}}")
+     "Empty dict: {}"
 
 Field names can be integers indicating positional arguments, such as
 ``{0}``, ``{1}``, etc. or names of keyword arguments.  You can also
 supply compound field names that read attributes or access dictionary keys::
 
-    import sys
-    'Platform: {0.platform}\nPython version: {0.version}'.format(sys) ->
-        'Platform: darwin\n
-         Python version: 2.6a1+ (trunk:61261M, Mar  5 2008, 20:29:41) \n
-         [GCC 4.0.1 (Apple Computer, Inc. build 5367)]'
-
-    import mimetypes
-    'Content-type: {0[.mp4]}'.format(mimetypes.types_map) ->
-        'Content-type: video/mp4'
+    >>> import sys
+    >>> print 'Platform: {0.platform}\nPython version: {0.version}'.format(sys)
+    Platform: darwin
+    Python version: 2.6a1+ (trunk:61261M, Mar  5 2008, 20:29:41) 
+    [GCC 4.0.1 (Apple Computer, Inc. build 5367)]'
+
+    >>> import mimetypes
+    >>> 'Content-type: {0[.mp4]}'.format(mimetypes.types_map)
+    'Content-type: video/mp4'
 
 Note that when using dictionary-style notation such as ``[.mp4]``, you
 don't need to put any quotation marks around the string; it will look
@@ -760,30 +761,25 @@
 resulting string.  The precise formatting used is also controllable by
 adding a colon followed by a format specifier.  For example::
 
-     # Field 0: left justify, pad to 15 characters
-     # Field 1: right justify, pad to 6 characters
-     fmt = '{0:15} ${1:>6}'
-
-     fmt.format('Registration', 35) ->
-       'Registration    $    35'
-
-     fmt.format('Tutorial', 50) ->
-       'Tutorial        $    50'
-
-     fmt.format('Banquet', 125) ->
-       'Banquet         $   125'
+     >>> # Field 0: left justify, pad to 15 characters
+     >>> # Field 1: right justify, pad to 6 characters
+     >>> fmt = '{0:15} ${1:>6}'
+     >>> fmt.format('Registration', 35)
+     'Registration    $    35'
+     >>> fmt.format('Tutorial', 50)
+     'Tutorial        $    50'
+     >>> fmt.format('Banquet', 125)
+     'Banquet         $   125'
 
 Format specifiers can reference other fields through nesting::
 
-    fmt = '{0:{1}}'
-
-    width = 15
-    fmt.format('Invoice #1234', width) ->
-      'Invoice #1234  '
-
-    width = 35
-    fmt.format('Invoice #1234', width) ->
-      'Invoice #1234                      '
+    >>> fmt = '{0:{1}}'
+    >>> width = 15
+    >>> fmt.format('Invoice #1234', width)
+    'Invoice #1234  '
+    >>> width = 35
+    >>> fmt.format('Invoice #1234', width)
+    'Invoice #1234                      '
 
 The alignment of a field within the desired width can be specified:
 
@@ -798,7 +794,7 @@
 
 Format specifiers can also include a presentation type, which
 controls how the value is formatted.  For example, floating-point numbers
-can be formatted as a general number or in exponential notation:
+can be formatted as a general number or in exponential notation::
 
     >>> '{0:g}'.format(3.75)
     '3.75'
@@ -806,25 +802,27 @@
     '3.750000e+00'
 
 A variety of presentation types are available.  Consult the 2.6
-documentation for a :ref:`complete list <formatstrings>`; here's a sample::
+documentation for a :ref:`complete list <formatstrings>`; here's a sample:
 
-        'b' - Binary. Outputs the number in base 2.
-        'c' - Character. Converts the integer to the corresponding
-              Unicode character before printing.
-        'd' - Decimal Integer. Outputs the number in base 10.
-        'o' - Octal format. Outputs the number in base 8.
-        'x' - Hex format. Outputs the number in base 16, using lower-
-              case letters for the digits above 9.
-        'e' - Exponent notation. Prints the number in scientific
-              notation using the letter 'e' to indicate the exponent.
-        'g' - General format. This prints the number as a fixed-point
-              number, unless the number is too large, in which case
-              it switches to 'e' exponent notation.
-        'n' - Number. This is the same as 'g' (for floats) or 'd' (for
-              integers), except that it uses the current locale setting to
-              insert the appropriate number separator characters.
-        '%' - Percentage. Multiplies the number by 100 and displays
-              in fixed ('f') format, followed by a percent sign.
+===== ========================================================================
+``b`` Binary. Outputs the number in base 2.
+``c`` Character. Converts the integer to the corresponding Unicode character
+      before printing.
+``d`` Decimal Integer. Outputs the number in base 10.
+``o`` Octal format. Outputs the number in base 8.
+``x`` Hex format. Outputs the number in base 16, using lower-case letters for
+      the digits above 9.
+``e`` Exponent notation. Prints the number in scientific notation using the
+      letter 'e' to indicate the exponent.
+``g`` General format. This prints the number as a fixed-point number, unless
+      the number is too large, in which case it switches to 'e' exponent
+      notation.
+``n`` Number. This is the same as 'g' (for floats) or 'd' (for integers),
+      except that it uses the current locale setting to insert the appropriate
+      number separator characters.
+``%`` Percentage. Multiplies the number by 100 and displays in fixed ('f')
+      format, followed by a percent sign.
+===== ========================================================================
 
 Classes and types can define a :meth:`__format__` method to control how they're
 formatted.  It receives a single argument, the format specifier::
@@ -865,13 +863,14 @@
 Python 2.6 has a ``__future__`` import that removes ``print`` as language
 syntax, letting you use the functional form instead.  For example::
 
-    from __future__ import print_function
-    print('# of entries', len(dictionary), file=sys.stderr)
+    >>> from __future__ import print_function
+    >>> print('# of entries', len(dictionary), file=sys.stderr)
 
 The signature of the new function is::
 
     def print(*args, sep=' ', end='\n', file=None)
 
+
 The parameters are:
 
  * *args*: positional arguments whose values will be printed out.
@@ -949,6 +948,20 @@
 Python 2.6 adds :class:`bytes` as a synonym for the :class:`str` type,
 and it also supports the ``b''`` notation.
 
+
+The 2.6 :class:`str` differs from 3.0's :class:`bytes` type in various
+ways; most notably, the constructor is completely different.  In 3.0,
+``bytes([65, 66, 67])`` is 3 elements long, containing the bytes
+representing ``ABC``; in 2.6, ``bytes([65, 66, 67])`` returns the
+12-byte string representing the :func:`str` of the list.
+
+The primary use of :class:`bytes` in 2.6 will be to write tests of
+object type such as ``isinstance(x, bytes)``.  This will help the 2to3
+converter, which can't tell whether 2.x code intends strings to
+contain either characters or 8-bit bytes; you can now 
+use either :class:`bytes` or :class:`str` to represent your intention 
+exactly, and the resulting code will also be correct in Python 3.0.
+
 There's also a ``__future__`` import that causes all string literals
 to become Unicode strings.  This means that ``\u`` escape sequences
 can be used to include Unicode characters::
@@ -988,6 +1001,8 @@
 and some of the methods of lists, such as :meth:`append`,
 :meth:`pop`,  and :meth:`reverse`.
 
+::
+
     >>> b = bytearray('ABC')
     >>> b.append('d')
     >>> b.append(ord('e'))
@@ -1210,8 +1225,8 @@
 now write::
 
     def func(d):
-	if not isinstance(d, collections.MutableMapping):
-	    raise ValueError("Mapping object expected, not %r" % d)
+        if not isinstance(d, collections.MutableMapping):
+            raise ValueError("Mapping object expected, not %r" % d)
 
 Don't feel that you must now begin writing lots of checks as in the
 above example.  Python has a strong tradition of duck-typing, where
@@ -1223,22 +1238,22 @@
 You can write your own ABCs by using ``abc.ABCMeta`` as the
 metaclass in a class definition::
 
-  from abc import ABCMeta, abstractmethod
+    from abc import ABCMeta, abstractmethod
 
-  class Drawable():
-      __metaclass__ = ABCMeta
+    class Drawable():
+        __metaclass__ = ABCMeta
 
-      @abstractmethod
-      def draw(self, x, y, scale=1.0):
-	  pass
+        @abstractmethod
+        def draw(self, x, y, scale=1.0):
+            pass
 
-      def draw_doubled(self, x, y):
-	  self.draw(x, y, scale=2.0)
+        def draw_doubled(self, x, y):
+            self.draw(x, y, scale=2.0)
 
 
-  class Square(Drawable):
-      def draw(self, x, y, scale):
-          ...
+    class Square(Drawable):
+        def draw(self, x, y, scale):
+            ...
 
 
 In the :class:`Drawable` ABC above, the :meth:`draw_doubled` method
@@ -1258,7 +1273,7 @@
     >>> class Circle(Drawable):
     ...     pass
     ...
-    >>> c=Circle()
+    >>> c = Circle()
     Traceback (most recent call last):
       File "<stdin>", line 1, in <module>
     TypeError: Can't instantiate abstract class Circle with abstract methods draw
@@ -1317,7 +1332,7 @@
 The :func:`int` and :func:`long` built-ins will now accept the "0o"
 and "0b" prefixes when base-8 or base-2 are requested, or when the
 *base* argument is zero (signalling that the base used should be
-determined from the string):
+determined from the string)::
 
     >>> int ('0o52', 0)
     42
@@ -1490,7 +1505,7 @@
   (Contributed by Alexander Belopolsky; :issue:`1686487`.)
 
   It's also become legal to provide keyword arguments after a ``*args`` argument
-  to a function call.
+  to a function call. ::
 
     >>> def f(*args, **kw):
     ...     print args, kw
@@ -1531,17 +1546,17 @@
   property. You would use them like this::
 
     class C(object):
-	@property
-	def x(self):
-	    return self._x
-
-	@x.setter
-	def x(self, value):
-	    self._x = value
-
-	@x.deleter
-	def x(self):
-	    del self._x
+        @property
+        def x(self):
+            return self._x
+
+        @x.setter
+        def x(self, value):
+            self._x = value
+
+        @x.deleter
+        def x(self):
+            del self._x
 
     class D(C):
         @C.x.getter
@@ -1864,8 +1879,8 @@
 
      >>> var_type = collections.namedtuple('variable',
      ...             'id name type size')
-     # Names are separated by spaces or commas.
-     # 'id, name, type, size' would also work.
+     >>> # Names are separated by spaces or commas.
+     >>> # 'id, name, type, size' would also work.
      >>> var_type._fields
      ('id', 'name', 'type', 'size')
 
@@ -1915,11 +1930,13 @@
 
 * A new window method in the :mod:`curses` module,
   :meth:`chgat`, changes the display attributes for a certain number of
-  characters on a single line.  (Contributed by Fabian Kreutz.)  ::
+  characters on a single line.  (Contributed by Fabian Kreutz.)
+  
+  ::
 
      # Boldface text starting at y=0,x=21
      # and affecting the rest of the line.
-     stdscr.chgat(0,21, curses.A_BOLD)
+     stdscr.chgat(0, 21, curses.A_BOLD)
 
   The :class:`Textbox` class in the :mod:`curses.textpad` module
   now supports editing in insert mode as well as overwrite mode.
@@ -1985,8 +2002,8 @@
   order, and returns a new generator that returns the contents of all
   the iterators, also in sorted order.  For example::
 
-     heapq.merge([1, 3, 5, 9], [2, 8, 16]) ->
-       [1, 2, 3, 5, 8, 9, 16]
+      >>> list(heapq.merge([1, 3, 5, 9], [2, 8, 16]))
+      [1, 2, 3, 5, 8, 9, 16]
 
   Another new function, ``heappushpop(heap, item)``,
   pushes *item* onto *heap*, then pops off and returns the smallest item.
@@ -2020,57 +2037,55 @@
   each of the elements; if some of the iterables are shorter than
   others, the missing values are set to *fillvalue*.  For example::
 
-     itertools.izip_longest([1,2,3], [1,2,3,4,5]) ->
-       (1, 1), (2, 2), (3, 3), (None, 4), (None, 5)
+     >>> tuple(itertools.izip_longest([1,2,3], [1,2,3,4,5]))
+     ((1, 1), (2, 2), (3, 3), (None, 4), (None, 5))
 
   ``product(iter1, iter2, ..., [repeat=N])`` returns the Cartesian product
   of the supplied iterables, a set of tuples containing
   every possible combination of the elements returned from each iterable. ::
 
-     itertools.product([1,2,3], [4,5,6]) ->
-        (1, 4), (1, 5), (1, 6),
-	(2, 4), (2, 5), (2, 6),
-	(3, 4), (3, 5), (3, 6)
+     >>> list(itertools.product([1,2,3], [4,5,6]))
+     [(1, 4), (1, 5), (1, 6),
+	  (2, 4), (2, 5), (2, 6),
+	  (3, 4), (3, 5), (3, 6)]
 
   The optional *repeat* keyword argument is used for taking the
   product of an iterable or a set of iterables with themselves,
   repeated *N* times.  With a single iterable argument, *N*-tuples
   are returned::
 
-     itertools.product([1,2], repeat=3) ->
-        (1, 1, 1), (1, 1, 2), (1, 2, 1), (1, 2, 2),
-        (2, 1, 1), (2, 1, 2), (2, 2, 1), (2, 2, 2)
+     >>> list(itertools.product([1,2], repeat=3))
+     [(1, 1, 1), (1, 1, 2), (1, 2, 1), (1, 2, 2),
+      (2, 1, 1), (2, 1, 2), (2, 2, 1), (2, 2, 2)]
 
   With two iterables, *2N*-tuples are returned. ::
 
-     itertools.product([1,2], [3,4], repeat=2) ->
-        (1, 3, 1, 3), (1, 3, 1, 4), (1, 3, 2, 3), (1, 3, 2, 4),
-        (1, 4, 1, 3), (1, 4, 1, 4), (1, 4, 2, 3), (1, 4, 2, 4),
-        (2, 3, 1, 3), (2, 3, 1, 4), (2, 3, 2, 3), (2, 3, 2, 4),
-        (2, 4, 1, 3), (2, 4, 1, 4), (2, 4, 2, 3), (2, 4, 2, 4)
+     >>> list(itertools.product([1,2], [3,4], repeat=2))
+     [(1, 3, 1, 3), (1, 3, 1, 4), (1, 3, 2, 3), (1, 3, 2, 4),
+      (1, 4, 1, 3), (1, 4, 1, 4), (1, 4, 2, 3), (1, 4, 2, 4),
+      (2, 3, 1, 3), (2, 3, 1, 4), (2, 3, 2, 3), (2, 3, 2, 4),
+      (2, 4, 1, 3), (2, 4, 1, 4), (2, 4, 2, 3), (2, 4, 2, 4)]
 
   ``combinations(iterable, r)`` returns sub-sequences of length *r* from
   the elements of *iterable*. ::
 
-    itertools.combinations('123', 2) ->
-       ('1', '2'), ('1', '3'), ('2', '3')
-
-    itertools.combinations('123', 3) ->
-       ('1', '2', '3')
-
-    itertools.combinations('1234', 3) ->
-       ('1', '2', '3'), ('1', '2', '4'), ('1', '3', '4'),
-       ('2', '3', '4')
+    >>> list(itertools.combinations('123', 2))
+    [('1', '2'), ('1', '3'), ('2', '3')]
+    >>> list(itertools.combinations('123', 3))
+    [('1', '2', '3')]
+    >>> list(itertools.combinations('1234', 3))
+    [('1', '2', '3'), ('1', '2', '4'),
+     ('1', '3', '4'), ('2', '3', '4')]
 
   ``permutations(iter[, r])`` returns all the permutations of length *r* of
   the iterable's elements.  If *r* is not specified, it will default to the
   number of elements produced by the iterable. ::
 
-    itertools.permutations([1,2,3,4], 2) ->
-       (1, 2), (1, 3), (1, 4),
-       (2, 1), (2, 3), (2, 4),
-       (3, 1), (3, 2), (3, 4),
-       (4, 1), (4, 2), (4, 3)
+    >>> list(itertools.permutations([1,2,3,4], 2))
+    [(1, 2), (1, 3), (1, 4),
+     (2, 1), (2, 3), (2, 4),
+     (3, 1), (3, 2), (3, 4),
+     (4, 1), (4, 2), (4, 3)]
 
   ``itertools.chain(*iterables)`` is an existing function in
   :mod:`itertools` that gained a new constructor in Python 2.6.
@@ -2079,8 +2094,8 @@
   then return all the elements of the first iterable, then
   all the elements of the second, and so on. ::
 
-    chain.from_iterable([[1,2,3], [4,5,6]]) ->
-        1, 2, 3, 4, 5, 6
+    >>> list(itertools.chain.from_iterable([[1,2,3], [4,5,6]]))
+    [1, 2, 3, 4, 5, 6]
 
   (All contributed by Raymond Hettinger.)
 
@@ -2251,16 +2266,15 @@
   with an installed Python package.  For example::
 
     >>> import pkgutil
-    >>> pkgutil.get_data('test', 'exception_hierarchy.txt')
-    'BaseException
+    >>> print pkgutil.get_data('test', 'exception_hierarchy.txt')
+    BaseException
      +-- SystemExit
      +-- KeyboardInterrupt
      +-- GeneratorExit
      +-- Exception
           +-- StopIteration
           +-- StandardError
-     ...'
-    >>>
+     ...
 
   (Contributed by Paul Moore; :issue:`2439`.)
 
@@ -2534,9 +2548,9 @@
 
       with test_support.check_warnings() as wrec:
           warnings.simplefilter("always")
-          ... code that triggers a warning ...
+          # ... code that triggers a warning ...
           assert str(wrec.message) == "function is outdated"
-	  assert len(wrec.warnings) == 1, "Multiple warnings raised"
+          assert len(wrec.warnings) == 1, "Multiple warnings raised"
 
   (Contributed by Brett Cannon.)
 
@@ -2710,7 +2724,7 @@
     t = ast.parse("""
     d = {}
     for i in 'abcdefghijklm':
-	d[i + i] = ord(i) - ord('a') + 1
+        d[i + i] = ord(i) - ord('a') + 1
     print d
     """)
     print ast.dump(t)
@@ -2719,32 +2733,32 @@
 
     Module(body=[
       Assign(targets=[
-	Name(id='d', ctx=Store())
+        Name(id='d', ctx=Store())
        ], value=Dict(keys=[], values=[]))
       For(target=Name(id='i', ctx=Store()),
-	  iter=Str(s='abcdefghijklm'), body=[
-	Assign(targets=[
-	  Subscript(value=
-	   Name(id='d', ctx=Load()),
-	     slice=
-	     Index(value=
-	    BinOp(left=Name(id='i', ctx=Load()), op=Add(),
-	     right=Name(id='i', ctx=Load()))), ctx=Store())
-	 ], value=
-	 BinOp(left=
-	  BinOp(left=
-	   Call(func=
-	    Name(id='ord', ctx=Load()), args=[
-	     Name(id='i', ctx=Load())
-	    ], keywords=[], starargs=None, kwargs=None),
-	   op=Sub(), right=Call(func=
-	    Name(id='ord', ctx=Load()), args=[
-	     Str(s='a')
-	    ], keywords=[], starargs=None, kwargs=None)),
-          op=Add(), right=Num(n=1)))
-       ], orelse=[])
-      Print(dest=None, values=[
-	Name(id='d', ctx=Load())
+          iter=Str(s='abcdefghijklm'), body=[
+        Assign(targets=[
+          Subscript(value=
+            Name(id='d', ctx=Load()),
+              slice=
+              Index(value=
+                BinOp(left=Name(id='i', ctx=Load()), op=Add(),
+                 right=Name(id='i', ctx=Load()))), ctx=Store())
+         ], value=
+         BinOp(left=
+          BinOp(left=
+           Call(func=
+            Name(id='ord', ctx=Load()), args=[
+              Name(id='i', ctx=Load())
+             ], keywords=[], starargs=None, kwargs=None),
+           op=Sub(), right=Call(func=
+            Name(id='ord', ctx=Load()), args=[
+              Str(s='a')
+             ], keywords=[], starargs=None, kwargs=None)),
+           op=Add(), right=Num(n=1)))
+        ], orelse=[])
+       Print(dest=None, values=[
+         Name(id='d', ctx=Load())
        ], nl=True)
      ])
 
@@ -2848,8 +2862,8 @@
 
     # Create data structure
     data_struct = dict(lastAccessed=datetime.datetime.now(),
-		       version=1,
-		       categories=('Personal','Shared','Private'))
+                       version=1,
+                       categories=('Personal','Shared','Private'))
 
     # Create string containing XML.
     plist_str = plistlib.writePlistToString(data_struct)
@@ -3260,7 +3274,7 @@
 .. ======================================================================
 
 
-.. _acks:
+.. _26acks:
 
 Acknowledgements
 ================

Modified: python/branches/tlee-ast-optimize/Lib/test/test_bisect.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_bisect.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_bisect.py	Sun Oct 12 14:40:01 2008
@@ -196,6 +196,17 @@
     def test_backcompatibility(self):
         self.assertEqual(self.module.insort, self.module.insort_right)
 
+    def test_listDerived(self):
+        class List(list):
+            data = []
+            def insert(self, index, item):
+                self.data.insert(index, item)
+
+        lst = List()
+        self.module.insort_left(lst, 10)
+        self.module.insort_right(lst, 5)
+        self.assertEqual([5, 10], lst.data)
+
 class TestInsortPython(TestInsort):
     module = py_bisect
 

Modified: python/branches/tlee-ast-optimize/Lib/test/test_poplib.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_poplib.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_poplib.py	Sun Oct 12 14:40:01 2008
@@ -1,43 +1,279 @@
-import socket
-import threading
+"""Test script for poplib module."""
+
+# Modified by Giampaolo Rodola' to give poplib.POP3 and poplib.POP3_SSL
+# a real test suite
+
 import poplib
+import threading
+import asyncore
+import asynchat
+import socket
+import os
 import time
 
 from unittest import TestCase
 from test import test_support
+from test.test_support import HOST
 
-HOST = test_support.HOST
 
-def server(evt, serv):
-    serv.listen(5)
-    try:
-        conn, addr = serv.accept()
-    except socket.timeout:
-        pass
-    else:
-        conn.send("+ Hola mundo\n")
-        conn.close()
-    finally:
-        serv.close()
-        evt.set()
+# the dummy data returned by server when LIST and RETR commands are issued
+LIST_RESP = '1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n.\r\n'
+RETR_RESP = """From: postmaster at python.org\
+\r\nContent-Type: text/plain\r\n\
+MIME-Version: 1.0\r\n\
+Subject: Dummy\r\n\
+\r\n\
+line1\r\n\
+line2\r\n\
+line3\r\n\
+.\r\n"""
+
+
+class DummyPOP3Handler(asynchat.async_chat):
+
+    def __init__(self, conn):
+        asynchat.async_chat.__init__(self, conn)
+        self.set_terminator("\r\n")
+        self.in_buffer = []
+        self.push('+OK dummy pop3 server ready.')
+
+    def collect_incoming_data(self, data):
+        self.in_buffer.append(data)
+
+    def found_terminator(self):
+        line = ''.join(self.in_buffer)
+        self.in_buffer = []
+        cmd = line.split(' ')[0].lower()
+        space = line.find(' ')
+        if space != -1:
+            arg = line[space + 1:]
+        else:
+            arg = ""
+        if hasattr(self, 'cmd_' + cmd):
+            method = getattr(self, 'cmd_' + cmd)
+            method(arg)
+        else:
+            self.push('-ERR unrecognized POP3 command "%s".' %cmd)
+
+    def handle_error(self):
+        raise
+
+    def push(self, data):
+        asynchat.async_chat.push(self, data + '\r\n')
+
+    def cmd_echo(self, arg):
+        # sends back the received string (used by the test suite)
+        self.push(arg)
+
+    def cmd_user(self, arg):
+        if arg != "guido":
+            self.push("-ERR no such user")
+        self.push('+OK password required')
+
+    def cmd_pass(self, arg):
+        if arg != "python":
+            self.push("-ERR wrong password")
+        self.push('+OK 10 messages')
+
+    def cmd_stat(self, arg):
+        self.push('+OK 10 100')
+
+    def cmd_list(self, arg):
+        if arg:
+            self.push('+OK %s %s' %(arg, arg))
+        else:
+            self.push('+OK')
+            asynchat.async_chat.push(self, LIST_RESP)
+
+    cmd_uidl = cmd_list
+
+    def cmd_retr(self, arg):
+        self.push('+OK %s bytes' %len(RETR_RESP))
+        asynchat.async_chat.push(self, RETR_RESP)
+
+    cmd_top = cmd_retr
+
+    def cmd_dele(self, arg):
+        self.push('+OK message marked for deletion.')
+
+    def cmd_noop(self, arg):
+        self.push('+OK done nothing.')
+
+    def cmd_rpop(self, arg):
+        self.push('+OK done nothing.')
+
+
+class DummyPOP3Server(asyncore.dispatcher, threading.Thread):
+
+    handler = DummyPOP3Handler
+
+    def __init__(self, address, af=socket.AF_INET):
+        threading.Thread.__init__(self)
+        asyncore.dispatcher.__init__(self)
+        self.create_socket(af, socket.SOCK_STREAM)
+        self.bind(address)
+        self.listen(5)
+        self.active = False
+        self.active_lock = threading.Lock()
+        self.host, self.port = self.socket.getsockname()[:2]
+
+    def start(self):
+        assert not self.active
+        self.__flag = threading.Event()
+        threading.Thread.start(self)
+        self.__flag.wait()
+
+    def run(self):
+        self.active = True
+        self.__flag.set()
+        while self.active and asyncore.socket_map:
+            self.active_lock.acquire()
+            asyncore.loop(timeout=0.1, count=1)
+            self.active_lock.release()
+        asyncore.close_all(ignore_all=True)
+
+    def stop(self):
+        assert self.active
+        self.active = False
+        self.join()
+
+    def handle_accept(self):
+        conn, addr = self.accept()
+        self.handler = self.handler(conn)
+        self.close()
+
+    def handle_connect(self):
+        self.close()
+    handle_read = handle_connect
+
+    def writable(self):
+        return 0
+
+    def handle_error(self):
+        raise
+
+
+class TestPOP3Class(TestCase):
 
-class GeneralTests(TestCase):
+    def assertOK(self, resp):
+        self.assertTrue(resp.startswith("+OK"))
+
+    def setUp(self):
+        self.server = DummyPOP3Server((HOST, 0))
+        self.server.start()
+        self.client = poplib.POP3(self.server.host, self.server.port)
+
+    def tearDown(self):
+        self.client.quit()
+        self.server.stop()
+
+    def test_getwelcome(self):
+        self.assertEqual(self.client.getwelcome(), '+OK dummy pop3 server ready.')
+
+    def test_exceptions(self):
+        self.assertRaises(poplib.error_proto, self.client._shortcmd, 'echo -err')
+
+    def test_user(self):
+        self.assertOK(self.client.user('guido'))
+        self.assertRaises(poplib.error_proto, self.client.user, 'invalid')
+
+    def test_pass_(self):
+        self.assertOK(self.client.pass_('python'))
+        self.assertRaises(poplib.error_proto, self.client.user, 'invalid')
+
+    def test_stat(self):
+        self.assertEqual(self.client.stat(), (10, 100))
+
+    def test_list(self):
+        self.assertEqual(self.client.list()[1:],
+                         (['1 1', '2 2', '3 3', '4 4', '5 5'], 25))
+        self.assertTrue(self.client.list('1').endswith("OK 1 1"))
+
+    def test_retr(self):
+        expected = ('+OK 116 bytes',
+                    ['From: postmaster at python.org', 'Content-Type: text/plain',
+                     'MIME-Version: 1.0', 'Subject: Dummy',
+                     '', 'line1', 'line2', 'line3'],
+                    113)
+        self.assertEqual(self.client.retr('foo'), expected)
+
+    def test_dele(self):
+        self.assertOK(self.client.dele('foo'))
+
+    def test_noop(self):
+        self.assertOK(self.client.noop())
+
+    def test_rpop(self):
+        self.assertOK(self.client.rpop('foo'))
+
+    def test_top(self):
+        expected =  ('+OK 116 bytes',
+                     ['From: postmaster at python.org', 'Content-Type: text/plain',
+                      'MIME-Version: 1.0', 'Subject: Dummy', '',
+                      'line1', 'line2', 'line3'],
+                     113)
+        self.assertEqual(self.client.top(1, 1), expected)
+
+    def test_uidl(self):
+        self.client.uidl()
+        self.client.uidl('foo')
+
+
+SUPPORTS_SSL = False
+if hasattr(poplib, 'POP3_SSL'):
+    import ssl
+
+    SUPPORTS_SSL = True
+    CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "keycert.pem")
+
+    class DummyPOP3_SSLHandler(DummyPOP3Handler):
+
+        def __init__(self, conn):
+            asynchat.async_chat.__init__(self, conn)
+            self.socket = ssl.wrap_socket(self.socket, certfile=CERTFILE,
+                                          server_side=True)
+            self.set_terminator("\r\n")
+            self.in_buffer = []
+            self.push('+OK dummy pop3 server ready.')
+
+    class TestPOP3_SSLClass(TestPOP3Class):
+        # repeat previous tests by using poplib.POP3_SSL
+
+        def setUp(self):
+            self.server = DummyPOP3Server((HOST, 0))
+            self.server.handler = DummyPOP3_SSLHandler
+            self.server.start()
+            self.client = poplib.POP3_SSL(self.server.host, self.server.port)
+
+        def test__all__(self):
+            self.assert_('POP3_SSL' in poplib.__all__)
+
+
+class TestTimeouts(TestCase):
 
     def setUp(self):
         self.evt = threading.Event()
         self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         self.sock.settimeout(3)
         self.port = test_support.bind_port(self.sock)
-        threading.Thread(target=server, args=(self.evt,self.sock)).start()
+        threading.Thread(target=self.server, args=(self.evt,self.sock)).start()
         time.sleep(.1)
 
     def tearDown(self):
         self.evt.wait()
 
-    def testBasic(self):
-        # connects
-        pop = poplib.POP3(HOST, self.port)
-        pop.sock.close()
+    def server(self, evt, serv):
+        serv.listen(5)
+        try:
+            conn, addr = serv.accept()
+        except socket.timeout:
+            pass
+        else:
+            conn.send("+ Hola mundo\n")
+            conn.close()
+        finally:
+            serv.close()
+            evt.set()
 
     def testTimeoutDefault(self):
         self.assertTrue(socket.getdefaulttimeout() is None)
@@ -65,8 +301,16 @@
         pop.sock.close()
 
 
-def test_main(verbose=None):
-    test_support.run_unittest(GeneralTests)
+def test_main():
+    tests = [TestPOP3Class, TestTimeouts]
+    if SUPPORTS_SSL:
+        tests.append(TestPOP3_SSLClass)
+    thread_info = test_support.threading_setup()
+    try:
+        test_support.run_unittest(*tests)
+    finally:
+        test_support.threading_cleanup(*thread_info)
+
 
 if __name__ == '__main__':
     test_main()

Modified: python/branches/tlee-ast-optimize/Makefile.pre.in
==============================================================================
--- python/branches/tlee-ast-optimize/Makefile.pre.in	(original)
+++ python/branches/tlee-ast-optimize/Makefile.pre.in	Sun Oct 12 14:40:01 2008
@@ -177,8 +177,8 @@
 BUILDPYTHON=	python$(BUILDEXE)
 
 # The task to run while instrument when building the profile-opt target
-PROFILE_TASK=	Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck
-#PROFILE_TASK=	Lib/test/regrtest.py
+PROFILE_TASK=	$(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck
+#PROFILE_TASK=	$(srcdir)/Lib/test/regrtest.py
 
 # === Definitions added by makesetup ===
 

Modified: python/branches/tlee-ast-optimize/Misc/NEWS
==============================================================================
--- python/branches/tlee-ast-optimize/Misc/NEWS	(original)
+++ python/branches/tlee-ast-optimize/Misc/NEWS	Sun Oct 12 14:40:01 2008
@@ -12,6 +12,10 @@
 Core and Builtins
 -----------------
 
+- On windows, os.chdir given unicode was not working if GetCurrentDirectoryW
+  returned a path longer than MAX_PATH. (But It's doubtful this code path is
+  really executed because I cannot move to such directory on win2k)
+
 - Issue #4069: When set.remove(element) is used with a set element, the element
   is temporarily replaced with an equivalent frozenset.  But the eventual
   KeyError would always report the empty frozenset([]) as the missing key. Now
@@ -20,6 +24,8 @@
 Library
 -------
 
+- Issue #3935: Properly support list subclasses in bisect's C implementation.
+
 - Issue #4014: Don't claim that Python has an Alpha release status, in addition
   to claiming it is Mature.
 

Modified: python/branches/tlee-ast-optimize/Modules/_bisectmodule.c
==============================================================================
--- python/branches/tlee-ast-optimize/Modules/_bisectmodule.c	(original)
+++ python/branches/tlee-ast-optimize/Modules/_bisectmodule.c	Sun Oct 12 14:40:01 2008
@@ -82,7 +82,7 @@
 	index = internal_bisect_right(list, item, lo, hi);
 	if (index < 0)
 		return NULL;
-	if (PyList_Check(list)) {
+	if (PyList_CheckExact(list)) {
 		if (PyList_Insert(list, index, item) < 0)
 			return NULL;
 	} else {
@@ -183,7 +183,7 @@
 	index = internal_bisect_left(list, item, lo, hi);
 	if (index < 0)
 		return NULL;
-	if (PyList_Check(list)) {
+	if (PyList_CheckExact(list)) {
 		if (PyList_Insert(list, index, item) < 0)
 			return NULL;
 	} else {

Modified: python/branches/tlee-ast-optimize/Modules/posixmodule.c
==============================================================================
--- python/branches/tlee-ast-optimize/Modules/posixmodule.c	(original)
+++ python/branches/tlee-ast-optimize/Modules/posixmodule.c	Sun Oct 12 14:40:01 2008
@@ -726,11 +726,16 @@
 	if (!result)
 		return FALSE;
 	if (result > MAX_PATH+1) {
-		new_path = malloc(result);
+		new_path = malloc(result * sizeof(wchar_t));
 		if (!new_path) {
 			SetLastError(ERROR_OUTOFMEMORY);
 			return FALSE;
 		}
+		result = GetCurrentDirectoryW(result, new_path);
+		if (!result) {
+			free(new_path);
+			return FALSE;
+		}
 	}
 	if (wcsncmp(new_path, L"\\\\", 2) == 0 ||
 	    wcsncmp(new_path, L"//", 2) == 0)


More information about the Python-checkins mailing list