~ubuntu-branches/ubuntu/lucid/python2.6/lucid

« back to all changes in this revision

Viewing changes to Doc/whatsnew/2.6.rst

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mto: (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20100311133019-sblbooa3uqrkoe70
Tags: upstream-2.6.5~rc2
ImportĀ upstreamĀ versionĀ 2.6.5~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
:Release: |release|
9
9
:Date: |today|
10
10
 
11
 
.. $Id: 2.6.rst 71282 2009-04-05 21:48:06Z georg.brandl $
 
11
.. $Id: 2.6.rst 78304 2010-02-22 14:55:17Z andrew.kuchling $
12
12
   Rules for maintenance:
13
13
 
14
14
   * Anyone can add text to this document.  Do not spend very much time
84
84
 
85
85
.. ========================================================================
86
86
.. Large, PEP-level features and changes should be described here.
87
 
.. Should there be a new section here for 3k migration?
88
 
.. Or perhaps a more general section describing module changes/deprecation?
89
87
.. ========================================================================
90
88
 
91
89
Python 3.0
348
346
 
349
347
* The code in *BLOCK* is executed.
350
348
 
351
 
* If *BLOCK* raises an exception, the :meth:`__exit__(type, value, traceback)`
352
 
  is called with the exception details, the same values returned by
353
 
  :func:`sys.exc_info`.  The method's return value controls whether the exception
 
349
* If *BLOCK* raises an exception, the context manager's :meth:`__exit__` method
 
350
  is called with three arguments, the exception details (``type, value, traceback``,
 
351
  the same values returned by :func:`sys.exc_info`, which can also be ``None``
 
352
  if no exception occurred).  The method's return value controls whether an exception
354
353
  is re-raised: any false value re-raises the exception, and ``True`` will result
355
354
  in suppressing it.  You'll only rarely want to suppress the exception, because
356
355
  if you do the author of the code containing the ':keyword:`with`' statement will
461
460
   with db_transaction(db) as cursor:
462
461
       ...
463
462
 
464
 
The :mod:`contextlib` module also has a :func:`nested(mgr1, mgr2, ...)` function
 
463
The :mod:`contextlib` module also has a ``nested(mgr1, mgr2, ...)`` function
465
464
that combines a number of context managers so you don't need to write nested
466
465
':keyword:`with`' statements.  In this example, the single ':keyword:`with`'
467
466
statement both starts a database transaction and acquires a thread lock::
470
469
   with nested (db_transaction(db), lock) as (cursor, locked):
471
470
       ...
472
471
 
473
 
Finally, the :func:`closing(object)` function returns *object* so that it can be
474
 
bound to a variable, and calls ``object.close`` at the end of the block. ::
 
472
Finally, the :func:`closing` function returns its argument so that it can be
 
473
bound to a variable, and calls the argument's ``.close()`` method at the end
 
474
of the block. ::
475
475
 
476
476
   import urllib, sys
477
477
   from contextlib import closing
680
680
        for N in range(1, 1000, 10):
681
681
            p.apply_async(factorial, (N, d))
682
682
 
683
 
    # Mark pool as closed -- no more tasks can be added.
684
 
    p.close()
685
 
 
686
 
    # Wait for tasks to exit
687
 
    p.join()
688
 
 
689
 
    # Output results
690
 
    for k, v in sorted(d.items()):
691
 
        print k, v
 
683
        # Mark pool as closed -- no more tasks can be added.
 
684
        p.close()
 
685
 
 
686
        # Wait for tasks to exit
 
687
        p.join()
 
688
 
 
689
        # Output results
 
690
        for k, v in sorted(d.items()):
 
691
            print k, v
692
692
 
693
693
This will produce the output::
694
694
 
1481
1481
 
1482
1482
Some smaller changes made to the core Python language are:
1483
1483
 
 
1484
* Directories and zip archives containing a :file:`__main__.py` file
 
1485
  can now be executed directly by passing their name to the
 
1486
  interpreter. The directory or zip archive is automatically inserted
 
1487
  as the first entry in sys.path.  (Suggestion and initial patch by
 
1488
  Andy Chu, subsequently revised by Phillip J. Eby and Nick Coghlan;
 
1489
  :issue:`1739468`.)
 
1490
 
1484
1491
* The :func:`hasattr` function was catching and ignoring all errors,
1485
1492
  under the assumption that they meant a :meth:`__getattr__` method
1486
1493
  was failing somehow and the return value of :func:`hasattr` would
1631
1638
  :cfunc:`PyObject_HashNotImplemented`.
1632
1639
  (Fixed by Nick Coghlan and Amaury Forgeot d'Arc; :issue:`2235`.)
1633
1640
 
1634
 
* Changes to the :class:`Exception` interface
1635
 
  as dictated by :pep:`352` continue to be made.  For 2.6,
1636
 
  the :attr:`message` attribute is being deprecated in favor of the
1637
 
  :attr:`args` attribute.
1638
 
 
1639
1641
* The :exc:`GeneratorExit` exception now subclasses
1640
1642
  :exc:`BaseException` instead of :exc:`Exception`.  This means
1641
1643
  that an exception handler that does ``except Exception:``
1772
1774
 
1773
1775
.. ======================================================================
1774
1776
 
1775
 
New, Improved, and Deprecated Modules
1776
 
=====================================
 
1777
New and Improved Modules
 
1778
========================
1777
1779
 
1778
1780
As in every release, Python's standard library received a number of
1779
1781
enhancements and bug fixes.  Here's a partial list of the most notable
1781
1783
:file:`Misc/NEWS` file in the source tree for a more complete list of
1782
1784
changes, or look through the Subversion logs for all the details.
1783
1785
 
1784
 
* (3.0-warning mode) Python 3.0 will feature a reorganized standard
1785
 
  library that will drop many outdated modules and rename others.
1786
 
  Python 2.6 running in 3.0-warning mode will warn about these modules
1787
 
  when they are imported.
1788
 
 
1789
 
  The list of deprecated modules is:
1790
 
  :mod:`audiodev`,
1791
 
  :mod:`bgenlocations`,
1792
 
  :mod:`buildtools`,
1793
 
  :mod:`bundlebuilder`,
1794
 
  :mod:`Canvas`,
1795
 
  :mod:`compiler`,
1796
 
  :mod:`dircache`,
1797
 
  :mod:`dl`,
1798
 
  :mod:`fpformat`,
1799
 
  :mod:`gensuitemodule`,
1800
 
  :mod:`ihooks`,
1801
 
  :mod:`imageop`,
1802
 
  :mod:`imgfile`,
1803
 
  :mod:`linuxaudiodev`,
1804
 
  :mod:`mhlib`,
1805
 
  :mod:`mimetools`,
1806
 
  :mod:`multifile`,
1807
 
  :mod:`new`,
1808
 
  :mod:`pure`,
1809
 
  :mod:`statvfs`,
1810
 
  :mod:`sunaudiodev`,
1811
 
  :mod:`test.testall`, and
1812
 
  :mod:`toaiff`.
1813
 
 
1814
1786
* The :mod:`asyncore` and :mod:`asynchat` modules are
1815
1787
  being actively maintained again, and a number of patches and bugfixes
1816
1788
  were applied.  (Maintained by Josiah Carlson; see :issue:`1736190` for
1826
1798
 
1827
1799
  The :mod:`bsddb.dbshelve` module now uses the highest pickling protocol
1828
1800
  available, instead of restricting itself to protocol 1.
1829
 
  (Contributed by W. Barnes; :issue:`1551443`.)
 
1801
  (Contributed by W. Barnes.)
1830
1802
 
1831
1803
* The :mod:`cgi` module will now read variables from the query string
1832
1804
  of an HTTP POST request.  This makes it possible to use form actions
1995
1967
  a Unicode path was used and Unicode filenames are matched within the
1996
1968
  directory.  (:issue:`1001604`)
1997
1969
 
1998
 
* The :mod:`gopherlib` module has been removed.
1999
 
 
2000
1970
* A new function in the :mod:`heapq` module, ``merge(iter1, iter2, ...)``,
2001
1971
  takes any number of iterables returning data in sorted
2002
1972
  order, and returns a new generator that returns the contents of all
2156
2126
 
2157
2127
  (Contributed by Christian Heimes and Mark Dickinson.)
2158
2128
 
2159
 
* The :mod:`MimeWriter` module and :mod:`mimify` module
2160
 
  have been deprecated; use the :mod:`email`
2161
 
  package instead.
2162
 
 
2163
 
* The :mod:`md5` module has been deprecated; use the :mod:`hashlib` module
2164
 
  instead.
2165
 
 
2166
2129
* :class:`mmap` objects now have a :meth:`rfind` method that searches for a
2167
2130
  substring beginning at the end of the string and searching
2168
2131
  backwards.  The :meth:`find` method also gained an *end* parameter
2245
2208
  and can optionally take new command-line arguments for the program.
2246
2209
  (Contributed by Rocky Bernstein; :issue:`1393667`.)
2247
2210
 
2248
 
* The :mod:`posixfile` module has been deprecated; :func:`fcntl.lockf`
2249
 
  provides better locking.
2250
 
 
2251
 
  The :func:`post_mortem` function, used to begin debugging a
 
2211
* The :func:`pdb.post_mortem` function, used to begin debugging a
2252
2212
  traceback, will now use the traceback returned by :func:`sys.exc_info`
2253
2213
  if no traceback is supplied.   (Contributed by Facundo Batista;
2254
2214
  :issue:`1106316`.)
2258
2218
  opcodes, returning a shorter pickle that contains the same data structure.
2259
2219
  (Contributed by Raymond Hettinger.)
2260
2220
 
2261
 
* The :mod:`popen2` module has been deprecated; use the :mod:`subprocess`
2262
 
  module.
2263
 
 
2264
2221
* A :func:`get_data` function was added to the :mod:`pkgutil`
2265
2222
  module that returns the contents of resource files included
2266
2223
  with an installed Python package.  For example::
2316
2273
  (Contributed by Guido van Rossum from work for Google App Engine;
2317
2274
  :issue:`3487`.)
2318
2275
 
2319
 
* The :mod:`rgbimg` module has been removed.
2320
 
 
2321
2276
* The :mod:`rlcompleter` module's :meth:`Completer.complete()` method
2322
2277
  will now ignore exceptions triggered while evaluating a name.
2323
2278
  (Fixed by Lorenz Quack; :issue:`2250`.)
2336
2291
  for that file.
2337
2292
  (Contributed by Christian Heimes; :issue:`1657`.)
2338
2293
 
2339
 
* The :mod:`sets` module has been deprecated; it's better to
2340
 
  use the built-in :class:`set` and :class:`frozenset` types.
2341
 
 
2342
 
* The :mod:`sha` module has been deprecated; use the :mod:`hashlib` module
2343
 
  instead.
2344
 
 
2345
2294
* The :func:`shutil.copytree` function now has an optional *ignore* argument
2346
2295
  that takes a callable object.  This callable will receive each directory path
2347
2296
  and a list of the directory's contents, and returns a list of names that
2404
2353
  e-mail between agents that don't manage a mail queue.  (LMTP
2405
2354
  implemented by Leif Hedstrom; :issue:`957003`.)
2406
2355
 
2407
 
  SMTP.starttls() now complies with :rfc:`3207` and forgets any
 
2356
  :meth:`SMTP.starttls` now complies with :rfc:`3207` and forgets any
2408
2357
  knowledge obtained from the server not obtained from the TLS
2409
2358
  negotiation itself.  (Patch contributed by Bill Fenner;
2410
2359
  :issue:`829951`.)
2414
2363
  environments.  TIPC addresses are 4- or 5-tuples.
2415
2364
  (Contributed by Alberto Bertogli; :issue:`1646`.)
2416
2365
 
2417
 
  A new function, :func:`create_connection`, takes an address
2418
 
  and connects to it using an optional timeout value, returning
2419
 
  the connected socket object.
 
2366
  A new function, :func:`create_connection`, takes an address and
 
2367
  connects to it using an optional timeout value, returning the
 
2368
  connected socket object.  This function also looks up the address's
 
2369
  type and connects to it using IPv4 or IPv6 as appropriate.  Changing
 
2370
  your code to use :func:`create_connection` instead of
 
2371
  ``socket(socket.AF_INET, ...)`` may be all that's required to make
 
2372
  your code work with IPv6.
2420
2373
 
2421
2374
* The base classes in the :mod:`SocketServer` module now support
2422
2375
  calling a :meth:`handle_timeout` method after a span of inactivity
2821
2774
often used in web applications. For more information about JSON, see
2822
2775
http://www.json.org.
2823
2776
 
2824
 
:mod:`json` comes with support for decoding and encoding most builtin Python
 
2777
:mod:`json` comes with support for decoding and encoding most built-in Python
2825
2778
types. The following example encodes and decodes a dictionary::
2826
2779
 
2827
2780
       >>> import json
2949
2902
 
2950
2903
.. ======================================================================
2951
2904
 
 
2905
Deprecations and Removals
 
2906
=========================
 
2907
 
 
2908
* String exceptions have been removed.  Attempting to use them raises a
 
2909
  :exc:`TypeError`.
 
2910
 
 
2911
* Changes to the :class:`Exception` interface
 
2912
  as dictated by :pep:`352` continue to be made.  For 2.6,
 
2913
  the :attr:`message` attribute is being deprecated in favor of the
 
2914
  :attr:`args` attribute.
 
2915
 
 
2916
* (3.0-warning mode) Python 3.0 will feature a reorganized standard
 
2917
  library that will drop many outdated modules and rename others.
 
2918
  Python 2.6 running in 3.0-warning mode will warn about these modules
 
2919
  when they are imported.
 
2920
 
 
2921
  The list of deprecated modules is:
 
2922
  :mod:`audiodev`,
 
2923
  :mod:`bgenlocations`,
 
2924
  :mod:`buildtools`,
 
2925
  :mod:`bundlebuilder`,
 
2926
  :mod:`Canvas`,
 
2927
  :mod:`compiler`,
 
2928
  :mod:`dircache`,
 
2929
  :mod:`dl`,
 
2930
  :mod:`fpformat`,
 
2931
  :mod:`gensuitemodule`,
 
2932
  :mod:`ihooks`,
 
2933
  :mod:`imageop`,
 
2934
  :mod:`imgfile`,
 
2935
  :mod:`linuxaudiodev`,
 
2936
  :mod:`mhlib`,
 
2937
  :mod:`mimetools`,
 
2938
  :mod:`multifile`,
 
2939
  :mod:`new`,
 
2940
  :mod:`pure`,
 
2941
  :mod:`statvfs`,
 
2942
  :mod:`sunaudiodev`,
 
2943
  :mod:`test.testall`, and
 
2944
  :mod:`toaiff`.
 
2945
 
 
2946
* The :mod:`gopherlib` module has been removed.
 
2947
 
 
2948
* The :mod:`MimeWriter` module and :mod:`mimify` module
 
2949
  have been deprecated; use the :mod:`email`
 
2950
  package instead.
 
2951
 
 
2952
* The :mod:`md5` module has been deprecated; use the :mod:`hashlib` module
 
2953
  instead.
 
2954
 
 
2955
* The :mod:`posixfile` module has been deprecated; :func:`fcntl.lockf`
 
2956
  provides better locking.
 
2957
 
 
2958
* The :mod:`popen2` module has been deprecated; use the :mod:`subprocess`
 
2959
  module.
 
2960
 
 
2961
* The :mod:`rgbimg` module has been removed.
 
2962
 
 
2963
* The :mod:`sets` module has been deprecated; it's better to
 
2964
  use the built-in :class:`set` and :class:`frozenset` types.
 
2965
 
 
2966
* The :mod:`sha` module has been deprecated; use the :mod:`hashlib` module
 
2967
  instead.
 
2968
 
 
2969
 
 
2970
.. ======================================================================
 
2971
 
2952
2972
 
2953
2973
Build and C API Changes
2954
2974
=======================
2975
2995
* The BerkeleyDB module now has a C API object, available as
2976
2996
  ``bsddb.db.api``.   This object can be used by other C extensions
2977
2997
  that wish to use the :mod:`bsddb` module for their own purposes.
2978
 
  (Contributed by Duncan Grisby; :issue:`1551895`.)
 
2998
  (Contributed by Duncan Grisby.)
2979
2999
 
2980
3000
* The new buffer interface, previously described in
2981
3001
  `the PEP 3118 section <#pep-3118-revised-buffer-protocol>`__,