rest25/whatsnew/2.5.rst => rest262/whatsnew/2.5.rst
f1****************************
n2-  What's New in Python 2.5  
n2+  What's New in Python 2.5
3****************************
4
5:Author: A.M. Kuchling
6
n7-.. |release| replace:: 1.0
n7+.. |release| replace:: 1.01
8
n9-.. % $Id: whatsnew25.tex 51743 2006-09-05 13:11:33Z andrew.kuchling $
n9+.. $Id: whatsnew25.tex 56611 2007-07-29 08:26:10Z georg.brandl $
10-.. % Fix XXX comments
10+.. Fix XXX comments
11
12This article explains the new features in Python 2.5.  The final release of
13Python 2.5 is scheduled for August 2006; :pep:`356` describes the planned
14release schedule.
15
16The changes in Python 2.5 are an interesting mix of language and library
17improvements. The library enhancements will be more important to Python's user
18community, I think, because several widely-useful packages were added.  New
n19-modules include ElementTree for XML processing (section :ref:`module-etree`),
n19+modules include ElementTree for XML processing (:mod:`xml.etree`),
20-the SQLite database module (section :ref:`module-sqlite`), and the :mod:`ctypes`
20+the SQLite database module (:mod:`sqlite`), and the :mod:`ctypes`
21-module for calling C functions (section :ref:`module-ctypes`).
21+module for calling C functions.
22
23The language changes are of middling significance.  Some pleasant new features
24were added, but most of them aren't features that you'll use every day.
25Conditional expressions were finally added to the language using a novel syntax;
26see section :ref:`pep-308`.  The new ':keyword:`with`' statement will make
27writing cleanup code easier (section :ref:`pep-343`).  Values can now be passed
28into generators (section :ref:`pep-342`).  Imports are now visible as either
29absolute or relative (section :ref:`pep-328`).  Some corner cases of exception
34As well as the language and library additions, other improvements and bugfixes
35were made throughout the source tree.  A search through the SVN change logs
36finds there were 353 patches applied and 458 bugs fixed between Python 2.4 and
372.5.  (Both figures are likely to be underestimates.)
38
39This article doesn't try to be a complete specification of the new features;
40instead changes are briefly introduced using helpful examples.  For full
41details, you should always refer to the documentation for Python 2.5 at
n42-`<http://docs.python.org>`_. If you want to understand the complete
n42+http://docs.python.org. If you want to understand the complete implementation
43-implementation and design rationale, refer to the PEP for a particular new
43+and design rationale, refer to the PEP for a particular new feature.
44-feature.
45
46Comments, suggestions, and error reports for this document are welcome; please
47e-mail them to the author or open a bug in the Python bug tracker.
48
n49-.. % ======================================================================
n48+.. ======================================================================
50
51
52.. _pep-308:
53
54PEP 308: Conditional Expressions
55================================
56
57For a long time, people have been requesting a way to write conditional
119
120
121.. seealso::
122
123   :pep:`308` - Conditional Expressions
124      PEP written by Guido van Rossum and Raymond D. Hettinger; implemented by Thomas
125      Wouters.
126
n127-.. % ======================================================================
n126+.. ======================================================================
128
129
130.. _pep-309:
131
132PEP 309: Partial Function Application
133=====================================
134
135The :mod:`functools` module is intended to contain tools for functional-style
197
198
199.. seealso::
200
201   :pep:`309` - Partial Function Application
202      PEP proposed and written by Peter Harris; implemented by Hye-Shik Chang and Nick
203      Coghlan, with adaptations by Raymond Hettinger.
204
n205-.. % ======================================================================
n204+.. ======================================================================
206
207
208.. _pep-314:
209
210PEP 314: Metadata for Python Software Packages v1.1
211===================================================
212
213Some simple dependency support was added to Distutils.  The :func:`setup`
216the dependency information will be recorded in the :file:`PKG-INFO` file.
217
218Another new keyword parameter is ``download_url``, which should be set to a URL
219for the package's source code.  This means it's now possible to look up an entry
220in the package index, determine the dependencies for a package, and download the
221required packages. ::
222
223   VERSION = '1.0'
n224-   setup(name='PyPackage', 
n223+   setup(name='PyPackage',
225         version=VERSION,
226         requires=['numarray', 'zlib (>=1.1.4)'],
227         obsoletes=['OldPackage']
228         download_url=('http://www.example.com/pypackage/dist/pkg-%s.tar.gz'
229                       % VERSION),
230        )
231
232Another new enhancement to the Python package index at
n233-`<http://cheeseshop.python.org>`_ is storing source and binary archives for a
n232+http://cheeseshop.python.org is storing source and binary archives for a
234package.  The new :command:`upload` Distutils command will upload a package to
235the repository.
236
237Before a package can be uploaded, you must be able to build a distribution using
238the :command:`sdist` Distutils command.  Once that works, you can run ``python
239setup.py upload`` to add your package to the PyPI archive.  Optionally you can
240GPG-sign the package by supplying the :option:`--sign` and :option:`--identity`
241options.
244
245
246.. seealso::
247
248   :pep:`314` - Metadata for Python Software Packages v1.1
249      PEP proposed and written by A.M. Kuchling, Richard Jones, and Fred Drake;
250      implemented by Richard Jones and Fred Drake.
251
n252-.. % ======================================================================
n251+.. ======================================================================
253
254
255.. _pep-328:
256
257PEP 328: Absolute and Relative Imports
258======================================
259
260The simpler part of PEP 328 was implemented in Python 2.4: parentheses could now
329.. seealso::
330
331   :pep:`328` - Imports: Multi-Line and Absolute/Relative
332      PEP written by Aahz; implemented by Thomas Wouters.
333
334   http://codespeak.net/py/current/doc/index.html
335      The py library by Holger Krekel, which contains the :mod:`py.std` package.
336
n337-.. % ======================================================================
n336+.. ======================================================================
338
339
340.. _pep-338:
341
342PEP 338: Executing Modules as Scripts
343=====================================
344
345The :option:`-m` switch added in Python 2.4 to execute a module as a script
355archive.
356
357
358.. seealso::
359
360   :pep:`338` - Executing modules as scripts
361      PEP written and  implemented by Nick Coghlan.
362
n363-.. % ======================================================================
n362+.. ======================================================================
364
365
366.. _pep-341:
367
368PEP 341: Unified try/except/finally
369===================================
370
371Until Python 2.5, the :keyword:`try` statement came in two flavours. You could
372use a :keyword:`finally` block to ensure that code is always executed, or one or
373more :keyword:`except` blocks to catch  specific exceptions.  You couldn't
374combine both :keyword:`except` blocks and a :keyword:`finally` block, because
375generating the right bytecode for the combined version was complicated and it
n376-wasn't clear what the semantics of the combined should be.
n375+wasn't clear what the semantics of the combined statement should be.
377
378Guido van Rossum spent some time working with Java, which does support the
379equivalent of combining :keyword:`except` blocks and a :keyword:`finally` block,
380and this clarified what the statement should mean.  In Python 2.5, you can now
381write::
382
383   try:
384       block-1 ...
385   except Exception1:
386       handler-1 ...
387   except Exception2:
388       handler-2 ...
389   else:
390       else-block
391   finally:
n392-       final-block 
n391+       final-block
393
394The code in *block-1* is executed.  If the code raises an exception, the various
395:keyword:`except` blocks are tested: if the exception is of class
396:class:`Exception1`, *handler-1* is executed; otherwise if it's of class
397:class:`Exception2`, *handler-2* is executed, and so forth.  If no exception is
398raised, the *else-block* is executed.
399
400No matter what happened previously, the *final-block* is executed once the code
403in the *final-block* is still run.
404
405
406.. seealso::
407
408   :pep:`341` - Unifying try-except and try-finally
409      PEP written by Georg Brandl;  implementation by Thomas Lee.
410
n411-.. % ======================================================================
n410+.. ======================================================================
412
413
414.. _pep-342:
415
416PEP 342: New Generator Features
417===============================
418
419Python 2.5 adds a simple way to pass values *into* a generator. As introduced in
481   >>> print it.next()
482   1
483   >>> print it.send(8)
484   8
485   >>> print it.next()
486   9
487   >>> print it.next()
488   Traceback (most recent call last):
n489-     File ``t.py'', line 15, in ?
n488+     File "t.py", line 15, in ?
490       print it.next()
491   StopIteration
492
n493-Because :keyword:`yield` will often be returning :const:`None`, you should
n492+:keyword:`yield` will usually return :const:`None`, so you should always check
494-always check for this case.  Don't just use its value in expressions unless
493+for this case.  Don't just use its value in expressions unless you're sure that
495-you're sure that the :meth:`send` method will be the only method used resume
494+the :meth:`send` method will be the only method used to resume your generator
496-your generator function.
495+function.
497
498In addition to :meth:`send`, there are two other new methods on generators:
499
500* :meth:`throw(type, value=None, traceback=None)` is used to raise an exception
501  inside the generator; the exception is raised by the :keyword:`yield` expression
502  where the generator's execution is paused.
503
504* :meth:`close` raises a new :exc:`GeneratorExit` exception inside the generator
n505-  to terminate the iteration.   On receiving this exception, the generator's code
n504+  to terminate the iteration.  On receiving this exception, the generator's code
506-  must either raise :exc:`GeneratorExit` or :exc:`StopIteration`; catching the
505+  must either raise :exc:`GeneratorExit` or :exc:`StopIteration`.  Catching the
507-  exception and doing anything else is illegal and will trigger a
506+  :exc:`GeneratorExit` exception and returning a value is illegal and will trigger
508-  :exc:`RuntimeError`.  :meth:`close` will also be called by  Python's garbage
507+  a :exc:`RuntimeError`; if the function raises some other exception, that
508+  exception is propagated to the caller.  :meth:`close` will also be called by
509-  collector when the generator is garbage-collected.
509+  Python's garbage collector when the generator is garbage-collected.
510
511  If you need to run cleanup code when a :exc:`GeneratorExit` occurs, I suggest
512  using a ``try: ... finally:`` suite instead of  catching :exc:`GeneratorExit`.
513
514The cumulative effect of these changes is to turn generators from one-way
515producers of information into both producers and consumers.
516
517Generators also become *coroutines*, a more generalized form of subroutines.
548      Hettinger and :pep:`325` by Samuele Pedroni.
549
550   http://en.wikipedia.org/wiki/Coroutine
551      The Wikipedia entry for  coroutines.
552
553   http://www.sidhe.org/~dan/blog/archives/000178.html
554      An explanation of coroutines from a Perl point of view, written by Dan Sugalski.
555
n556-.. % ======================================================================
n556+.. ======================================================================
557
558
559.. _pep-343:
560
561PEP 343: The 'with' statement
562=============================
563
564The ':keyword:`with`' statement clarifies code that previously would use
569
570The ':keyword:`with`' statement is a new control-flow structure whose basic
571structure is::
572
573   with expression [as variable]:
574       with-block
575
576The expression is evaluated, and it should result in an object that supports the
n577-context management protocol.  This object may return a value that can optionally
n577+context management protocol (that is, has :meth:`__enter__` and :meth:`__exit__`
578+methods.
579+ 
580+The object's :meth:`__enter__` is called before *with-block* is executed and
581+therefore can run set-up code. It also may return a value that is bound to the
578-be bound to the name *variable*.  (Note carefully that *variable* is *not*
582+name *variable*, if given.  (Note carefully that *variable* is *not* assigned
579-assigned the result of *expression*.)  The object can then run set-up code
583+the result of *expression*.)
580-before *with-block* is executed and some clean-up code is executed after the
581-block is done, even if the block raised an exception.
582
n585+After execution of the *with-block* is finished, the object's :meth:`__exit__`
586+method is called, even if the block raised an exception, and can therefore run
587+clean-up code.
588+ 
583-To enable the statement in Python 2.5, you need  to add the following directive
589+To enable the statement in Python 2.5, you need to add the following directive
584to your module::
585
586   from __future__ import with_statement
587
588The statement will always be enabled in Python 2.6.
589
590Some standard Python objects now support the context management protocol and can
591be used with the ':keyword:`with`' statement. File objects are one example::
592
593   with open('/etc/passwd', 'r') as f:
594       for line in f:
595           print line
596           ... more processing code ...
597
598After this statement has executed, the file object in *f* will have been
n599-automatically closed, even if the 'for' loop raised an exception part-way
n605+automatically closed, even if the :keyword:`for` loop raised an exception part-
600-through the block.
606+way through the block.
607+ 
608+.. note::
609+ 
610+   In this case, *f* is the same object created by :func:`open`, because
611+   :meth:`file.__enter__` returns *self*.
601
602The :mod:`threading` module's locks and condition variables  also support the
603':keyword:`with`' statement::
604
605   lock = threading.Lock()
606   with lock:
607       # Critical section of code
608       ...
621   print v.sqrt()
622
623   with localcontext(Context(prec=16)):
624       # All code in this block uses a precision of 16 digits.
625       # The original context is restored on exiting the block.
626       print v.sqrt()
627
628
n629-.. _context-managers:
n640+.. _new-25-context-managers:
630
631Writing Context Managers
632------------------------
633
634Under the hood, the ':keyword:`with`' statement is fairly complicated. Most
635people will only use ':keyword:`with`' in company with existing objects and
636don't need to know these details, so you can skip the rest of this section if
637you like.  Authors of new objects will need to understand the details of the
720               # No exception, so commit
721               self.commit()
722           else:
723               # Exception occurred, so rollback.
724               self.rollback()
725               # return False
726
727
n728-.. _module-contextlib:
n739+.. _contextlibmod:
729
730The contextlib module
731---------------------
732
733The new :mod:`contextlib` module provides some functions and a decorator that
734are useful for writing objects for use with the ':keyword:`with`' statement.
735
736The decorator is called :func:`contextmanager`, and lets you write a single
785.. seealso::
786
787   :pep:`343` - The "with" statement
788      PEP written by Guido van Rossum and Nick Coghlan; implemented by Mike Bland,
789      Guido van Rossum, and Neal Norwitz.  The PEP shows the code generated for a
790      ':keyword:`with`' statement, which can be helpful in learning how the statement
791      works.
792
n793-   ../lib/module-contextlib.html
794-      The documentation  for the :mod:`contextlib` module.
804+   The documentation  for the :mod:`contextlib` module.
795
n796-.. % ======================================================================
n806+.. ======================================================================
797
798
799.. _pep-352:
800
801PEP 352: Exceptions as New-Style Classes
802========================================
803
804Exception classes can now be new-style classes, not just classic classes, and
820hitting Control-C or code calling :func:`sys.exit`.  A bare ``except:`` will
821catch all exceptions, so you commonly need to list :exc:`KeyboardInterrupt` and
822:exc:`SystemExit` in order to re-raise them.  The usual pattern is::
823
824   try:
825       ...
826   except (KeyboardInterrupt, SystemExit):
827       raise
n828-   except: 
n838+   except:
829-       # Log error...  
839+       # Log error...
830       # Continue running program...
831
832In Python 2.5, you can now write ``except Exception`` to achieve the same
833result, catching all the exceptions that usually indicate errors  but leaving
834:exc:`KeyboardInterrupt` and :exc:`SystemExit` alone.  As in previous versions,
835a bare ``except:`` still catches all exceptions.
836
837The goal for Python 3.0 is to require any class raised as an exception to derive
847to be able to remove the string-exception feature in a few releases.
848
849
850.. seealso::
851
852   :pep:`352` - Required Superclass for Exceptions
853      PEP written by  Brett Cannon and Guido van Rossum; implemented by Brett Cannon.
854
n855-.. % ======================================================================
n865+.. ======================================================================
856
857
858.. _pep-353:
859
860PEP 353: Using ssize_t as the index type
861========================================
862
863A wide-ranging change to Python's C API, using a new  :ctype:`Py_ssize_t` type
866platforms.
867
868Various pieces of the Python interpreter used C's :ctype:`int` type to store
869sizes or counts; for example, the number of items in a list or tuple were stored
870in an :ctype:`int`.  The C compilers for most 64-bit platforms still define
871:ctype:`int` as a 32-bit type, so that meant that lists could only hold up to
872``2**31 - 1`` = 2147483647 items. (There are actually a few different
873programming models that 64-bit C compilers can use -- see
n874-`<http://www.unix.org/version2/whatsnew/lp64_wp.html>`_ for a discussion -- but
n884+http://www.unix.org/version2/whatsnew/lp64_wp.html for a discussion -- but the
875-the most commonly available model leaves :ctype:`int` as 32 bits.)
885+most commonly available model leaves :ctype:`int` as 32 bits.)
876
877A limit of 2147483647 items doesn't really matter on a 32-bit platform because
878you'll run out of memory before hitting the length limit. Each list item
879requires space for a pointer, which is 4 bytes, plus space for a
880:ctype:`PyObject` representing the item.  2147483647\*4 is already more bytes
881than a 32-bit address space can contain.
882
883It's possible to address that much memory on a 64-bit platform, however.  The
906read to learn about supporting 64-bit platforms.
907
908
909.. seealso::
910
911   :pep:`353` - Using ssize_t as the index type
912      PEP written and implemented by Martin von Löwis.
913
n914-.. % ======================================================================
n924+.. ======================================================================
915
916
917.. _pep-357:
918
919PEP 357: The '__index__' method
920===============================
921
922The NumPy developers had a problem that could only be solved by adding a new
932:meth:`__int__`, floating-point numbers would also become legal slice indexes
933and that's clearly an undesirable behaviour.
934
935Instead, a new special method called :meth:`__index__` was added.  It takes no
936arguments and returns an integer giving the slice index to use.  For example::
937
938   class C:
939       def __index__ (self):
n940-           return self.value  
n950+           return self.value
941
942The return value must be either a Python integer or long integer. The
943interpreter will check that the type returned is correct, and raises a
944:exc:`TypeError` if this requirement isn't met.
945
946A corresponding :attr:`nb_index` slot was added to the C-level
947:ctype:`PyNumberMethods` structure to let C extensions implement this protocol.
948:cfunc:`PyNumber_Index(obj)` can be used in extension code to call the
949:meth:`__index__` function and retrieve its result.
950
951
952.. seealso::
953
954   :pep:`357` - Allowing Any Object to be Used for Slicing
955      PEP written  and implemented by Travis Oliphant.
956
n957-.. % ======================================================================
n967+.. ======================================================================
958
959
960.. _other-lang:
961
962Other Language Changes
963======================
964
965Here are all of the changes that Python 2.5 makes to the core Python language.
1009* The :meth:`startswith` and :meth:`endswith` methods of string types now accept
1010  tuples of strings to check for. ::
1011
1012     def is_image_file (filename):
1013         return filename.endswith(('.gif', '.jpg', '.tiff'))
1014
1015  (Implemented by Georg Brandl following a suggestion by Tom Lynn.)
1016
n1017-  .. % RFE #1491485
n1027+  .. RFE #1491485
1018
1019* The :func:`min` and :func:`max` built-in functions gained a ``key`` keyword
1020  parameter analogous to the ``key`` argument for :meth:`sort`.  This parameter
1021  supplies a function that takes a single argument and is called for every value
1022  in the list; :func:`min`/:func:`max` will return the element with the
1023  smallest/largest return value from this function. For example, to find the
1024  longest string in a list, you can do::
1025
1026     L = ['medium', 'longest', 'short']
1027     # Prints 'longest'
n1028-     print max(L, key=len)              
n1038+     print max(L, key=len)
1029     # Prints 'short', because lexicographically 'short' has the largest value
n1030-     print max(L)         
n1040+     print max(L)
1031
1032  (Contributed by Steven Bethard and Raymond Hettinger.)
1033
1034* Two new built-in functions, :func:`any` and :func:`all`, evaluate whether an
1035  iterator contains any true or false values.  :func:`any` returns :const:`True`
1036  if any value returned by the iterator is true; otherwise it will return
1037  :const:`False`.  :func:`all` returns :const:`True` only if all of the values
1038  returned by the iterator evaluate as true. (Suggested by Guido van Rossum, and
1039  implemented by Raymond Hettinger.)
1040
n1041-* The result of a class's :meth:`__hash__` method can now  be either a long
n1051+* The result of a class's :meth:`__hash__` method can now be either a long
1042  integer or a regular integer.  If a long integer is returned, the hash of that
n1043-  value is taken.  In earlier versions the hash value was required to be a regular
n1053+  value is taken.  In earlier versions the hash value was required to be a
1044-  integer, but in 2.5 the :func:`id` built-in was changed to always return non-
1054+  regular integer, but in 2.5 the :func:`id` built-in was changed to always
1045-  negative numbers, and users often seem to use ``id(self)`` in :meth:`__hash__`
1055+  return non-negative numbers, and users often seem to use ``id(self)`` in
1046-  methods (though this is discouraged).
1056+  :meth:`__hash__` methods (though this is discouraged).
1047
n1048-  .. % Bug #1536021
n1058+  .. Bug #1536021
1049
1050* ASCII is now the default encoding for modules.  It's now  a syntax error if a
1051  module contains string literals with 8-bit characters but doesn't have an
1052  encoding declaration.  In Python 2.4 this triggered a warning, not a syntax
1053  error.  See :pep:`263`  for how to declare a module's encoding; for example, you
1054  might add  a line like this near the top of the source file::
1055
1056     # -*- coding: latin1 -*-
1057
1058* A new warning, :class:`UnicodeWarning`, is triggered when  you attempt to
1059  compare a Unicode string and an 8-bit string  that can't be converted to Unicode
1060  using the default ASCII encoding.   The result of the comparison is false::
1061
1062     >>> chr(128) == unichr(128)   # Can't convert chr(128) to Unicode
n1063-     __main__:1: UnicodeWarning: Unicode equal comparison failed 
n1073+     __main__:1: UnicodeWarning: Unicode equal comparison failed
1064-       to convert both arguments to Unicode - interpreting them 
1074+       to convert both arguments to Unicode - interpreting them
1065       as being unequal
1066     False
1067     >>> chr(127) == unichr(127)   # chr(127) can be converted
1068     True
1069
1070  Previously this would raise a :class:`UnicodeDecodeError` exception, but in 2.5
1071  this could result in puzzling problems when accessing a dictionary.  If you
1072  looked up ``unichr(128)`` and ``chr(128)`` was being used as a key, you'd get a
1091* The list of base classes in a class definition can now be empty.   As an
1092  example, this is now legal::
1093
1094     class C():
1095         pass
1096
1097  (Implemented by Brett Cannon.)
1098
n1099-.. % ======================================================================
n1109+.. ======================================================================
1100
1101
n1102-.. _interactive:
n1112+.. _25interactive:
1103
1104Interactive Interpreter Changes
1105-------------------------------
1106
1107In the interactive interpreter, ``quit`` and ``exit``  have long been strings so
1108that new users get a somewhat helpful message when they try to quit::
1109
1110   >>> quit
1114representations of themselves, but are also callable. Newbies who try ``quit()``
1115or ``exit()`` will now exit the interpreter as they expect.  (Implemented by
1116Georg Brandl.)
1117
1118The Python executable now accepts the standard long options  :option:`--help`
1119and :option:`--version`; on Windows,  it also accepts the :option:`/?` option
1120for displaying a help message. (Implemented by Georg Brandl.)
1121
n1122-.. % ======================================================================
n1132+.. ======================================================================
1123
1124
1125.. _opts:
1126
1127Optimizations
1128-------------
1129
1130Several of the optimizations were developed at the NeedForSpeed sprint, an event
1140  by Raymond Hettinger.)
1141
1142* The speed of some Unicode operations, such as finding substrings, string
1143  splitting, and character map encoding and decoding, has been improved.
1144  (Substring search and splitting improvements were added by Fredrik Lundh and
1145  Andrew Dalke at the NeedForSpeed sprint. Character maps were improved by Walter
1146  Dörwald and Martin von Löwis.)
1147
n1148-  .. % Patch 1313939, 1359618
n1158+  .. Patch 1313939, 1359618
1149
1150* The :func:`long(str, base)` function is now faster on long digit strings
1151  because fewer intermediate results are calculated.  The peak is for strings of
1152  around 800--1000 digits where  the function is 6 times faster. (Contributed by
1153  Alan McIntyre and committed at the NeedForSpeed sprint.)
1154
n1155-  .. % Patch 1442927
n1165+  .. Patch 1442927
1166+ 
1167+* It's now illegal to mix iterating over a file  with ``for line in file`` and
1168+  calling  the file object's :meth:`read`/:meth:`readline`/:meth:`readlines`
1169+  methods.  Iteration uses an internal buffer and the  :meth:`read\*` methods
1170+  don't use that buffer.   Instead they would return the data following the
1171+  buffer, causing the data to appear out of order.  Mixing iteration and these
1172+  methods will now trigger a :exc:`ValueError` from the :meth:`read\*` method.
1173+  (Implemented by Thomas Wouters.)
1174+ 
1175+  .. Patch 1397960
1156
1157* The :mod:`struct` module now compiles structure format  strings into an
1158  internal representation and caches this representation, yielding a 20% speedup.
1159  (Contributed by Bob Ippolito at the NeedForSpeed sprint.)
1160
1161* The :mod:`re` module got a 1 or 2% speedup by switching to  Python's allocator
1162  functions instead of the system's  :cfunc:`malloc` and :cfunc:`free`.
1163  (Contributed by Jack Diederich at the NeedForSpeed sprint.)
1169
1170* Function calls are now faster because code objects now keep  the most recently
1171  finished frame (a "zombie frame") in an internal field of the code object,
1172  reusing it the next time the code object is invoked.  (Original patch by Michael
1173  Hudson, modified by Armin Rigo and Richard Jones; committed at the NeedForSpeed
1174  sprint.)  Frame objects are also slightly smaller, which may improve cache
1175  locality and reduce memory usage a bit.  (Contributed by Neal Norwitz.)
1176
n1177-  .. % Patch 876206
n1197+  .. Patch 876206
1178-  .. % Patch 1337051
1198+  .. Patch 1337051
1179
1180* Python's built-in exceptions are now new-style classes, a change that speeds
1181  up instantiation considerably.  Exception handling in Python 2.5 is therefore
1182  about 30% faster than in 2.4. (Contributed by Richard Jones, Georg Brandl and
1183  Sean Reifschneider at the NeedForSpeed sprint.)
1184
1185* Importing now caches the paths tried, recording whether  they exist or not so
1186  that the interpreter makes fewer  :cfunc:`open` and :cfunc:`stat` calls on
1187  startup. (Contributed by Martin von Löwis and Georg Brandl.)
1188
n1189-  .. % Patch 921466
n1209+  .. Patch 921466
1190
n1191-.. % ======================================================================
n1211+.. ======================================================================
1192
1193
n1194-.. _modules:
n1214+.. _25modules:
1195
1196New, Improved, and Removed Modules
1197==================================
1198
1199The standard library received many enhancements and bug fixes in Python 2.5.
1200Here's a partial list of the most notable changes, sorted alphabetically by
1201module name. Consult the :file:`Misc/NEWS` file in the source tree for a more
1202complete list of changes, or look through the SVN logs for all the details.
1209  of a tuple. :class:`CodecInfo` instances behave like a 4-tuple to preserve
1210  backward compatibility but also have the attributes :attr:`encode`,
1211  :attr:`decode`, :attr:`incrementalencoder`, :attr:`incrementaldecoder`,
1212  :attr:`streamwriter`, and :attr:`streamreader`.  Incremental codecs  can receive
1213  input and produce output in multiple chunks; the output is the same as if the
1214  entire input was fed to the non-incremental codec. See the :mod:`codecs` module
1215  documentation for details. (Designed and implemented by Walter Dörwald.)
1216
n1217-  .. % Patch  1436130
n1237+  .. Patch  1436130
1218
1219* The :mod:`collections` module gained a new type, :class:`defaultdict`, that
1220  subclasses the standard :class:`dict` type.  The new type mostly behaves like a
1221  dictionary but constructs a default value when a key isn't present,
1222  automatically adding it to the dictionary for the requested key value.
1223
1224  The first argument to :class:`defaultdict`'s constructor is a factory function
1225  that gets called whenever a key is requested but not found. This factory
1234     index = defaultdict(list)
1235
1236     for w in words:
1237         init_letter = w[0]
1238         index[init_letter].append(w)
1239
1240  Printing ``index`` results in the following output::
1241
n1242-     defaultdict(<type 'list'>, {'c': ['cammin', 'che'], 'e': ['era'], 
n1262+     defaultdict(<type 'list'>, {'c': ['cammin', 'che'], 'e': ['era'],
1243-             'd': ['del', 'di', 'diritta'], 'm': ['mezzo', 'mi'], 
1263+             'd': ['del', 'di', 'diritta'], 'm': ['mezzo', 'mi'],
1244-             'l': ['la'], 'o': ['oscura'], 'n': ['nel', 'nostra'], 
1264+             'l': ['la'], 'o': ['oscura'], 'n': ['nel', 'nostra'],
1245-             'p': ['per'], 's': ['selva', 'smarrita'], 
1265+             'p': ['per'], 's': ['selva', 'smarrita'],
1246             'r': ['ritrovai'], 'u': ['una'], 'v': ['vita', 'via']}
1247
1248  (Contributed by Guido van Rossum.)
1249
1250* The :class:`deque` double-ended queue type supplied by the :mod:`collections`
1251  module now has a :meth:`remove(value)` method that removes the first occurrence
1252  of *value* in the queue, raising :exc:`ValueError` if the value isn't found.
1253  (Contributed by Raymond Hettinger.)
1254
1255* New module: The :mod:`contextlib` module contains helper functions for use
n1256-  with the new ':keyword:`with`' statement.  See section :ref:`module-contextlib`
n1276+  with the new ':keyword:`with`' statement.  See section :ref:`contextlibmod`
1257  for more about this module.
1258
1259* New module: The :mod:`cProfile` module is a C implementation of  the existing
1260  :mod:`profile` module that has much lower overhead. The module's interface is
1261  the same as :mod:`profile`: you run ``cProfile.run('main()')`` to profile a
1262  function, can save profile data to a file, etc.  It's not yet known if the
1263  Hotshot profiler, which is also written in C but doesn't match the
1264  :mod:`profile` module's interface, will continue to be maintained in future
1306  being executed at all.  This is intended for code snippets that are usage
1307  examples intended for the reader and aren't actually test cases.
1308
1309  An *encoding* parameter was added to the :func:`testfile` function and the
1310  :class:`DocFileSuite` class to specify the file's encoding.  This makes it
1311  easier to use non-ASCII characters in  tests contained within a docstring.
1312  (Contributed by Bjorn Tillenius.)
1313
n1314-  .. % Patch 1080727
n1334+  .. Patch 1080727
1315
1316* The :mod:`email` package has been updated to version 4.0. (Contributed by
1317  Barry Warsaw.)
1318
n1319-  .. % XXX need to provide some more detail here
n1339+  .. XXX need to provide some more detail here
1320
1321* The :mod:`fileinput` module was made more flexible. Unicode filenames are now
1322  supported, and a *mode* parameter that defaults to ``"r"`` was added to the
1323  :func:`input` function to allow opening files in binary or universal-newline
1324  mode.  Another new parameter, *openhook*, lets you use a function other than
1325  :func:`open`  to open the input files.  Once you're iterating over  the set of
1326  files, the :class:`FileInput` object's new :meth:`fileno` returns the file
1327  descriptor for the currently opened file. (Contributed by Georg Brandl.)
1369  :func:`format_string` function that works like :func:`format` but also supports
1370  mixing %char specifiers with arbitrary text.
1371
1372  A new :func:`currency` function was also added that formats a number according
1373  to the current locale's settings.
1374
1375  (Contributed by Georg Brandl.)
1376
n1377-  .. % Patch 1180296
n1397+  .. Patch 1180296
1378
1379* The :mod:`mailbox` module underwent a massive rewrite to add the capability to
1380  modify mailboxes in addition to reading them.  A new set of classes that include
1381  :class:`mbox`, :class:`MH`, and :class:`Maildir` are used to read mailboxes, and
1382  have an :meth:`add(message)` method to add messages, :meth:`remove(key)` to
1383  remove messages, and :meth:`lock`/:meth:`unlock` to lock/unlock the mailbox.
1384  The following example converts a maildir-format mailbox into an mbox-format
1385  one::
1437  :func:`resource.getrusage` function. :func:`wait4(pid)` does take a process ID.
1438  (Contributed by Chad J. Schroeder.)
1439
1440  On FreeBSD, the :func:`os.stat` function now returns  times with nanosecond
1441  resolution, and the returned object now has :attr:`st_gen` and
1442  :attr:`st_birthtime`. The :attr:`st_flags` member is also available, if the
1443  platform supports it. (Contributed by Antti Louko and  Diego Pettenò.)
1444
n1445-  .. % (Patch 1180695, 1212117)
n1465+  .. (Patch 1180695, 1212117)
1446
1447* The Python debugger provided by the :mod:`pdb` module can now store lists of
1448  commands to execute when a breakpoint is reached and execution stops.  Once
1449  breakpoint #1 has been created, enter ``commands 1`` and enter a series of
1450  commands to be executed, finishing the list with ``end``.  The command list can
1451  include commands that resume execution, such as ``continue`` or ``next``.
1452  (Contributed by Grégoire Dooms.)
1453
n1454-  .. % Patch 790710
n1474+  .. Patch 790710
1455
1456* The :mod:`pickle` and :mod:`cPickle` modules no longer accept a return value
1457  of ``None`` from the :meth:`__reduce__` method; the method must return a tuple
1458  of arguments instead.  The ability to return ``None`` was deprecated in Python
1459  2.4, so this completes the removal of the feature.
1460
1461* The :mod:`pkgutil` module, containing various utility functions for finding
1462  packages, was enhanced to support PEP 302's import hooks and now also works for
1468  detailed measurement of the interpreter's speed.  It times particular operations
1469  such as function calls, tuple slicing, method lookups, and numeric operations,
1470  instead of performing many different operations and reducing the result to a
1471  single number as :file:`pystone.py` does.
1472
1473* The :mod:`pyexpat` module now uses version 2.0 of the Expat parser.
1474  (Contributed by Trent Mick.)
1475
n1496+* The :class:`Queue` class provided by the :mod:`Queue` module gained two new
1497+  methods.  :meth:`join` blocks until all items in the queue have been retrieved
1498+  and all processing work on the items  have been completed.  Worker threads call
1499+  the other new method,  :meth:`task_done`, to signal that processing for an item
1500+  has been completed.  (Contributed by Raymond Hettinger.)
1501+ 
1476* The old :mod:`regex` and :mod:`regsub` modules, which have been  deprecated
1477  ever since Python 2.0, have finally been deleted.   Other deleted modules:
1478  :mod:`statcache`, :mod:`tzparse`, :mod:`whrandom`.
1479
1480* Also deleted: the :file:`lib-old` directory, which includes ancient modules
1481  such as :mod:`dircmp` and :mod:`ni`, was removed.  :file:`lib-old` wasn't on the
1482  default ``sys.path``, so unless your programs explicitly added the directory to
1483  ``sys.path``, this removal shouldn't affect your code.
1484
1485* The :mod:`rlcompleter` module is no longer  dependent on importing the
1486  :mod:`readline` module and therefore now works on non-Unix platforms. (Patch
1487  from Robert Kiendl.)
1488
n1489-  .. % Patch #1472854
n1515+  .. Patch #1472854
1490
1491* The :mod:`SimpleXMLRPCServer` and :mod:`DocXMLRPCServer`  classes now have a
1492  :attr:`rpc_paths` attribute that constrains XML-RPC operations to a limited set
1493  of URL paths; the default is to allow only ``'/'`` and ``'/RPC2'``.  Setting
1494  :attr:`rpc_paths` to ``None`` or an empty tuple disables  this path checking.
1495
n1496-  .. % Bug #1473048
n1522+  .. Bug #1473048
1497
1498* The :mod:`socket` module now supports :const:`AF_NETLINK` sockets on Linux,
1499  thanks to a patch from Philippe Biondi.   Netlink sockets are a Linux-specific
1500  mechanism for communications between a user-space process and kernel code; an
n1501-  introductory  article about them is at
n1527+  introductory  article about them is at http://www.linuxjournal.com/article/7356.
1502-  `<http://www.linuxjournal.com/article/7356>`_. In Python code, netlink addresses
1528+  In Python code, netlink addresses are represented as a tuple of 2 integers,
1503-  are represented as a tuple of 2 integers,  ``(pid, group_mask)``.
1529+  ``(pid, group_mask)``.
1504
n1505-  Two new methods on socket objects, :meth:`recv_buf(buffer)` and
n1531+  Two new methods on socket objects, :meth:`recv_into(buffer)` and
1506-  :meth:`recvfrom_buf(buffer)`, store the received data in an object  that
1532+  :meth:`recvfrom_into(buffer)`, store the received data in an object  that
1507  supports the buffer protocol instead of returning the data as a string.  This
1508  means you can put the data directly into an array or a memory-mapped file.
1509
1510  Socket objects also gained :meth:`getfamily`, :meth:`gettype`, and
1511  :meth:`getproto` accessor methods to retrieve the family, type, and protocol
1512  values for the socket.
1513
1514* New module: the :mod:`spwd` module provides functions for accessing the shadow
1554* The :class:`TarFile` class in the :mod:`tarfile` module now has an
1555  :meth:`extractall` method that extracts all members from the archive into the
1556  current working directory.  It's also possible to set a different directory as
1557  the extraction target, and to unpack only a subset of the archive's members.
1558
1559  The compression used for a tarfile opened in stream mode can now be autodetected
1560  using the mode ``'r|*'``. (Contributed by Lars Gustäbel.)
1561
n1562-  .. % patch 918101
n1588+  .. patch 918101
1563
1564* The :mod:`threading` module now lets you set the stack size used when new
1565  threads are created. The :func:`stack_size([*size*])` function returns the
1566  currently configured stack size, and supplying the optional *size* parameter
1567  sets a new value.  Not all platforms support changing the stack size, but
1568  Windows, POSIX threading, and OS/2 all do. (Contributed by Andrew MacIntyre.)
1569
n1570-  .. % Patch 1454481
n1596+  .. Patch 1454481
1571
1572* The :mod:`unicodedata` module has been updated to use version 4.1.0 of the
1573  Unicode character database.  Version 3.2.0 is required  by some specifications,
1574  so it's still available as  :attr:`unicodedata.ucd_3_2_0`.
1575
1576* New module: the  :mod:`uuid` module generates  universally unique identifiers
1577  (UUIDs) according to :rfc:`4122`.  The RFC defines several different UUID
1578  versions that are generated from a starting string, from system properties, or
1612  there are a number of switches  to control the behaviour (:option:`-n` for a new
1613  browser window,  :option:`-t` for a new tab).  New module-level functions,
1614  :func:`open_new` and :func:`open_new_tab`, were added  to support this.  The
1615  module's :func:`open` function supports an additional feature, an *autoraise*
1616  parameter that signals whether to raise the open window when possible. A number
1617  of additional browsers were added to the supported list such as Firefox, Opera,
1618  Konqueror, and elinks.  (Contributed by Oleg Broytmann and Georg Brandl.)
1619
n1620-  .. % Patch #754022
n1646+  .. Patch #754022
1621
1622* The :mod:`xmlrpclib` module now supports returning  :class:`datetime` objects
1623  for the XML-RPC date type.  Supply  ``use_datetime=True`` to the :func:`loads`
1624  function or the :class:`Unmarshaller` class to enable this feature. (Contributed
1625  by Skip Montanaro.)
1626
n1627-  .. % Patch 1120353
n1653+  .. Patch 1120353
1628
1629* The :mod:`zipfile` module now supports the ZIP64 version of the  format,
1630  meaning that a .zip archive can now be larger than 4 GiB and can contain
1631  individual files larger than 4 GiB.  (Contributed by Ronald Oussoren.)
1632
n1633-  .. % Patch 1446489
n1659+  .. Patch 1446489
1634
1635* The :mod:`zlib` module's :class:`Compress` and :class:`Decompress` objects now
1636  support a :meth:`copy` method that makes a copy of the  object's internal state
1637  and returns a new  :class:`Compress` or :class:`Decompress` object.
1638  (Contributed by Chris AtLee.)
1639
n1640-  .. % Patch 1435422
n1666+  .. Patch 1435422
1641
n1642-.. % ======================================================================
n1668+.. ======================================================================
1643
1644
1645.. _module-ctypes:
1646
1647The ctypes package
1648------------------
1649
1650The :mod:`ctypes` package, written by Thomas Heller, has been added  to the
1713modules, now that :mod:`ctypes` is included with core Python.
1714
1715
1716.. seealso::
1717
1718   http://starship.python.net/crew/theller/ctypes/
1719      The ctypes web page, with a tutorial, reference, and FAQ.
1720
n1721-   ../lib/module-ctypes.html
1722-      The documentation  for the :mod:`ctypes` module.
1747+   The documentation  for the :mod:`ctypes` module.
1723
n1724-.. % ======================================================================
n1749+.. ======================================================================
1725
1726
1727.. _module-etree:
1728
1729The ElementTree package
1730-----------------------
1731
1732A subset of Fredrik Lundh's ElementTree library for processing XML has been
1733added to the standard library as :mod:`xml.etree`.  The available modules are
1734:mod:`ElementTree`, :mod:`ElementPath`, and :mod:`ElementInclude` from
1735ElementTree 1.2.6.    The :mod:`cElementTree` accelerator module is also
1736included.
1737
1738The rest of this section will provide a brief overview of using ElementTree.
1739Full documentation for ElementTree is available at
n1740-`<http://effbot.org/zone/element-index.htm>`_.
n1765+http://effbot.org/zone/element-index.htm.
1741
1742ElementTree represents an XML document as a tree of element nodes. The text
1743content of the document is stored as the :attr:`.text` and :attr:`.tail`
1744attributes of  (This is one of the major differences between ElementTree and
1745the Document Object Model; in the DOM there are many different types of node,
1746including :class:`TextNode`.)
1747
1748The most commonly used parsing function is :func:`parse`, that takes either a
1833read the package's official documentation for more details.
1834
1835
1836.. seealso::
1837
1838   http://effbot.org/zone/element-index.htm
1839      Official documentation for ElementTree.
1840
n1841-.. % ======================================================================
n1866+.. ======================================================================
1842
1843
1844.. _module-hashlib:
1845
1846The hashlib package
1847-------------------
1848
1849A new :mod:`hashlib` module, written by Gregory P. Smith,  has been added to
1854
1855The old :mod:`md5` and :mod:`sha` modules still exist as wrappers around hashlib
1856to preserve backwards compatibility.  The new module's interface is very close
1857to that of the old modules, but not identical. The most significant difference
1858is that the constructor functions for creating new hashing objects are named
1859differently. ::
1860
1861   # Old versions
n1862-   h = md5.md5()   
n1887+   h = md5.md5()
1863-   h = md5.new()   
1888+   h = md5.new()
1864
n1865-   # New version 
n1890+   # New version
1866   h = hashlib.md5()
1867
1868   # Old versions
n1869-   h = sha.sha()   
n1894+   h = sha.sha()
1870-   h = sha.new()   
1895+   h = sha.new()
1871
n1872-   # New version 
n1897+   # New version
1873   h = hashlib.sha1()
1874
1875   # Hash that weren't previously available
1876   h = hashlib.sha224()
1877   h = hashlib.sha256()
1878   h = hashlib.sha384()
1879   h = hashlib.sha512()
1880
1885:meth:`update(string)` hashes the specified string into the  current digest
1886state, :meth:`digest` and :meth:`hexdigest` return the digest value as a binary
1887string or a string of hex digits, and :meth:`copy` returns a new hashing object
1888with the same digest state.
1889
1890
1891.. seealso::
1892
n1893-   ../lib/module-hashlib.html
1894-      The documentation  for the :mod:`hashlib` module.
1918+   The documentation  for the :mod:`hashlib` module.
1895
n1896-.. % ======================================================================
n1920+.. ======================================================================
1897
1898
1899.. _module-sqlite:
1900
1901The sqlite3 package
1902-------------------
1903
n1904-The pysqlite module (`<http://www.pysqlite.org>`_), a wrapper for the SQLite
n1928+The pysqlite module (http://www.pysqlite.org), a wrapper for the SQLite embedded
1905-embedded database, has been added to the standard library under the package name
1929+database, has been added to the standard library under the package name
1906:mod:`sqlite3`.
1907
n1908-SQLite is a C library that provides a SQL-language database that stores data in
n1932+SQLite is a C library that provides a lightweight disk-based database that
1909-disk files without requiring a separate server process. pysqlite was written by
1933+doesn't require a separate server process and allows accessing the database
1910-Gerhard Häring and provides a SQL interface compliant with the DB-API 2.0
1934+using a nonstandard variant of the SQL query language. Some applications can use
1911-specification described by :pep:`249`. This means that it should be possible to
1935+SQLite for internal data storage.  It's also possible to prototype an
1912-write the first version of your applications using SQLite for data storage.  If
1936+application using SQLite and then port the code to a larger database such as
1913-switching to a larger database such as PostgreSQL or Oracle is later necessary,
1937+PostgreSQL or Oracle.
1914-the switch should be relatively easy.
1938+ 
1939+pysqlite was written by Gerhard Häring and provides a SQL interface compliant
1940+with the DB-API 2.0 specification described by :pep:`249`.
1915
1916If you're compiling the Python source yourself, note that the source tree
1917doesn't include the SQLite code, only the wrapper module. You'll need to have
1918the SQLite libraries and headers installed before compiling Python, and the
1919build process will compile the module when the necessary headers are available.
1920
1921To use the module, you must first create a :class:`Connection` object that
1922represents the database.  Here the data will be stored in the
1928
1929Once you have a :class:`Connection`, you can create a :class:`Cursor`  object
1930and call its :meth:`execute` method to perform SQL commands::
1931
1932   c = conn.cursor()
1933
1934   # Create table
1935   c.execute('''create table stocks
n1936-   (date timestamp, trans varchar, symbol varchar,
n1962+   (date text, trans text, symbol text,
1937-    qty decimal, price decimal)''')
1963+    qty real, price real)''')
1938
1939   # Insert a row of data
1940   c.execute("""insert into stocks
1941             values ('2006-01-05','BUY','RHAT',100,35.14)""")
1942
1943Usually your SQL operations will need to use values from Python variables.  You
1944shouldn't assemble your query using Python's string operations because doing so
1945is insecure; it makes your program vulnerable to an SQL injection attack.
1978   ...
1979   (u'2006-01-05', u'BUY', u'RHAT', 100, 35.140000000000001)
1980   (u'2006-03-28', u'BUY', u'IBM', 1000, 45.0)
1981   (u'2006-04-06', u'SELL', u'IBM', 500, 53.0)
1982   (u'2006-04-05', u'BUY', u'MSOFT', 1000, 72.0)
1983   >>>
1984
1985For more information about the SQL dialect supported by SQLite, see
n1986-`<http://www.sqlite.org>`_.
n2012+http://www.sqlite.org.
1987
1988
1989.. seealso::
1990
1991   http://www.pysqlite.org
1992      The pysqlite web page.
1993
1994   http://www.sqlite.org
1995      The SQLite web page; the documentation describes the syntax and the available
1996      data types for the supported SQL dialect.
1997
n1998-   ../lib/module-sqlite3.html
1999-      The documentation  for the :mod:`sqlite3` module.
2024+   The documentation  for the :mod:`sqlite3` module.
2000
2001   :pep:`249` - Database API Specification 2.0
2002      PEP written by Marc-André Lemburg.
2003
n2004-.. % ======================================================================
n2029+.. ======================================================================
2005
2006
2007.. _module-wsgiref:
2008
2009The wsgiref package
2010-------------------
2011
2012The Web Server Gateway Interface (WSGI) v1.0 defines a standard interface
2013between web servers and Python web applications and is described in :pep:`333`.
2014The :mod:`wsgiref` package is a reference implementation of the WSGI
2015specification.
2016
n2017-.. % XXX should this be in a PEP 333 section instead?
n2042+.. XXX should this be in a PEP 333 section instead?
2018
2019The package includes a basic HTTP server that will run a WSGI application; this
2020server is useful for debugging but isn't intended for  production use.  Setting
2021up a server takes only a few lines of code::
2022
2023   from wsgiref import simple_server
2024
2025   wsgi_app = ...
2026
2027   host = ''
2028   port = 8000
2029   httpd = simple_server.make_server(host, port, wsgi_app)
2030   httpd.serve_forever()
2031
n2032-.. % XXX discuss structure of WSGI applications?
n2057+.. XXX discuss structure of WSGI applications?
2033-.. % XXX provide an example using Django or some other framework?
2058+.. XXX provide an example using Django or some other framework?
2034
2035
2036.. seealso::
2037
2038   http://www.wsgi.org
2039      A central web site for WSGI-related resources.
2040
2041   :pep:`333` - Python Web Server Gateway Interface v1.0
2042      PEP written by Phillip J. Eby.
2043
n2044-.. % ======================================================================
n2069+.. ======================================================================
2045
2046
2047.. _build-api:
2048
2049Build and C API Changes
2050=======================
2051
2052Changes to Python's build process and to the C API include:
2054* The Python source tree was converted from CVS to Subversion,  in a complex
2055  migration procedure that was supervised and flawlessly carried out by Martin von
2056  Löwis.  The procedure was developed as :pep:`347`.
2057
2058* Coverity, a company that markets a source code analysis tool called Prevent,
2059  provided the results of their examination of the Python source code.  The
2060  analysis found about 60 bugs that  were quickly fixed.  Many of the bugs were
2061  refcounting problems, often occurring in error-handling code.  See
n2062-  `<http://scan.coverity.com>`_ for the statistics.
n2087+  http://scan.coverity.com for the statistics.
2063
2064* The largest change to the C API came from :pep:`353`, which modifies the
2065  interpreter to use a :ctype:`Py_ssize_t` type definition instead of
2066  :ctype:`int`.  See the earlier section :ref:`pep-353` for a discussion of this
2067  change.
2068
2069* The design of the bytecode compiler has changed a great deal,  no longer
2070  generating bytecode by traversing the parse tree.  Instead the parse tree is
2095  more information, read the source code, and then ask questions on python-dev.
2096
2097  The AST code was developed under Jeremy Hylton's management, and implemented by
2098  (in alphabetical order) Brett Cannon, Nick Coghlan, Grant Edwards, John
2099  Ehresman, Kurt Kaiser, Neal Norwitz, Tim Peters, Armin Rigo, and Neil
2100  Schemenauer, plus the participants in a number of AST sprints at conferences
2101  such as PyCon.
2102
n2103-  .. % List of names taken from Jeremy's python-dev post at
n2128+  .. List of names taken from Jeremy's python-dev post at
2104-  .. % http://mail.python.org/pipermail/python-dev/2005-October/057500.html
2129+  .. http://mail.python.org/pipermail/python-dev/2005-October/057500.html
2105
2106* Evan Jones's patch to obmalloc, first described in a talk at PyCon DC 2005,
2107  was applied.  Python 2.4 allocated small objects in 256K-sized arenas, but never
2108  freed arenas.  With this patch, Python will free arenas when they're empty.  The
2109  net effect is that on some platforms, when you allocate many objects, Python's
2110  memory usage may actually drop when you delete them and the memory may be
2111  returned to the operating system.  (Implemented by Evan Jones, and reworked by
2112  Tim Peters.)
2161  compiled with a C++ compiler without errors.   (Implemented by Anthony Baxter,
2162  Martin von Löwis, Skip Montanaro.)
2163
2164* The :cfunc:`PyRange_New` function was removed.  It was never documented, never
2165  used in the core code, and had dangerously lax error checking.  In the unlikely
2166  case that your extensions were using it, you can replace it by something like
2167  the following::
2168
n2169-     range = PyObject_CallFunction((PyObject*) &PyRange_Type, "lll", 
n2194+     range = PyObject_CallFunction((PyObject*) &PyRange_Type, "lll",
2170                                   start, stop, step);
2171
n2172-.. % ======================================================================
n2197+.. ======================================================================
2173
2174
2175.. _ports:
2176
2177Port-Specific Changes
2178---------------------
2179
2180* MacOS X (10.3 and higher): dynamic loading of modules now uses the
2181  :cfunc:`dlopen` function instead of MacOS-specific functions.
2182
n2183-* MacOS X: a :option:`--enable-universalsdk` switch was added to the
n2208+* MacOS X: an :option:`--enable-universalsdk` switch was added to the
2184  :program:`configure` script that compiles the interpreter as a universal binary
2185  able to run on both PowerPC and Intel processors. (Contributed by Ronald
n2186-  Oussoren.)
n2211+  Oussoren; :issue:`2573`.)
2187
2188* Windows: :file:`.dll` is no longer supported as a filename extension for
2189  extension modules.  :file:`.pyd` is now the only filename extension that will be
2190  searched for.
2191
n2192-.. % ======================================================================
n2217+.. ======================================================================
2193
2194
2195.. _porting:
2196
2197Porting to Python 2.5
2198=====================
2199
2200This section lists previously described changes that may require changes to your
2239  the same change to avoid warnings and to support 64-bit machines.  See the
2240  earlier section :ref:`pep-353` for a discussion of this change.
2241
2242* C API:  The obmalloc changes mean that  you must be careful to not mix usage
2243  of the :cfunc:`PyMem_\*` and :cfunc:`PyObject_\*` families of functions. Memory
2244  allocated with  one family's :cfunc:`\*_Malloc` must be  freed with the
2245  corresponding family's :cfunc:`\*_Free` function.
2246
n2247-.. % ======================================================================
n2272+.. ======================================================================
2248
t2249- 
2250-.. _acks:
2251
2252Acknowledgements
2253================
2254
2255The author would like to thank the following people for offering suggestions,
2256corrections and assistance with various drafts of this article: Georg Brandl,
2257Nick Coghlan, Phillip J. Eby, Lars Gustäbel, Raymond Hettinger, Ralf W. Grosse-
2258Kunstleve, Kent Johnson, Iain Lowe, Martin von Löwis, Fredrik Lundh, Andrew
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op