rest25/whatsnew/2.3.rst => rest262/whatsnew/2.3.rst
f1****************************
n2-  What's New in Python 2.3  
n2+  What's New in Python 2.3
3****************************
4
5:Author: A.M. Kuchling
6
7.. |release| replace:: 1.01
8
n9-.. % $Id: whatsnew23.tex 50964 2006-07-30 03:03:43Z fred.drake $
n9+.. $Id: whatsnew23.tex 54631 2007-03-31 11:58:36Z georg.brandl $
10
11This article explains the new features in Python 2.3.  Python 2.3 was released
12on July 29, 2003.
13
14The main themes for Python 2.3 are polishing some of the features added in 2.2,
15adding various small but useful enhancements to the core language, and expanding
16the standard library.  The new object model introduced in the previous version
17has benefited from 18 months of bugfixes and from optimization efforts that have
25support for the long-awaited Python catalog, an updated version of IDLE, and
26modules for logging messages, wrapping text, parsing CSV files, processing
27command-line options, using BerkeleyDB databases...  the list of new and
28enhanced modules is lengthy.
29
30This article doesn't attempt to provide a complete specification of the new
31features, but instead provides a convenient overview.  For full details, you
32should refer to the documentation for Python 2.3, such as the Python Library
n33-Reference (XXX reference: ../lib/lib.html) and the Python Reference Manual (XXX
n33+Reference and the Python Reference Manual.  If you want to understand the
34-reference: ../ref/ref.html).  If you want to understand the complete
35-implementation and design rationale,  refer to the PEP for a particular new
34+complete implementation and design rationale, refer to the PEP for a particular
36-feature.
35+new feature.
37
n38-.. % ======================================================================
n37+.. ======================================================================
39
40
41PEP 218: A Standard Set Datatype
42================================
43
44The new :mod:`sets` module contains an implementation of a set datatype.  The
45:class:`Set` class is for mutable sets, sets that can have members added and
46removed.  The :class:`ImmutableSet` class is for sets that can't be modified,
113
114
115.. seealso::
116
117   :pep:`218` - Adding a Built-In Set Object Type
118      PEP written by Greg V. Wilson. Implemented by Greg V. Wilson, Alex Martelli, and
119      GvR.
120
n121-.. % ======================================================================
n120+.. ======================================================================
122
123
124.. _section-generators:
125
126PEP 255: Simple Generators
127==========================
128
129In Python 2.2, generators were added as an optional feature, to be enabled by a
214               yield x
215
216Two other examples in :file:`Lib/test/test_generators.py` produce solutions for
217the N-Queens problem (placing $N$ queens on an $NxN$ chess board so that no
218queen threatens another) and the Knight's Tour (a route that takes a knight to
219every square of an $NxN$ chessboard without visiting any square twice).
220
221The idea of generators comes from other programming languages, especially Icon
n222-(`<http://www.cs.arizona.edu/icon/>`_), where the idea of generators is central.
n221+(http://www.cs.arizona.edu/icon/), where the idea of generators is central.  In
223-In Icon, every expression and function call behaves like a generator.  One
222+Icon, every expression and function call behaves like a generator.  One example
224-example from "An Overview of the Icon Programming Language" at
223+from "An Overview of the Icon Programming Language" at
225-`<http://www.cs.arizona.edu/icon/docs/ipd266.htm>`_ gives an idea of what this
224+http://www.cs.arizona.edu/icon/docs/ipd266.htm gives an idea of what this looks
226-looks like::
225+like::
227
228   sentence := "Store it in the neighboring harbor"
229   if (i := find("or", sentence)) > 5 then write(i)
230
231In Icon the :func:`find` function returns the indexes at which the substring
232"or" is found: 3, 23, 33.  In the :keyword:`if` statement, ``i`` is first
233assigned a value of 3, but 3 is less than 5, so the comparison fails, and Icon
234retries it with the second value of 23.  23 is greater than 5, so the comparison
244
245
246.. seealso::
247
248   :pep:`255` - Simple Generators
249      Written by Neil Schemenauer, Tim Peters, Magnus Lie Hetland.  Implemented mostly
250      by Neil Schemenauer and Tim Peters, with other fixes from the Python Labs crew.
251
n252-.. % ======================================================================
n251+.. ======================================================================
253
254
255.. _section-encodings:
256
257PEP 263: Source Code Encodings
258==============================
259
260Python source files can now be declared as being in different character set
278
279
280.. seealso::
281
282   :pep:`263` - Defining Python Source Code Encodings
283      Written by Marc-André Lemburg and Martin von Löwis; implemented by Suzuki Hisao
284      and Martin von Löwis.
285
n286-.. % ======================================================================
n285+.. ======================================================================
287
288
289PEP 273: Importing Modules from ZIP Archives
290============================================
291
292The new :mod:`zipimport` module adds support for importing modules from a ZIP-
293format archive.  You don't need to import the module explicitly; it will be
294automatically imported if a ZIP archive's filename is added to ``sys.path``.
297   amk@nyman:~/src/python$ unzip -l /tmp/example.zip
298   Archive:  /tmp/example.zip
299     Length     Date   Time    Name
300    --------    ----   ----    ----
301        8467  11-26-02 22:30   jwzthreading.py
302    --------                   -------
303        8467                   1 file
304   amk@nyman:~/src/python$ ./python
n305-   Python 2.3 (#1, Aug 1 2003, 19:54:32) 
n304+   Python 2.3 (#1, Aug 1 2003, 19:54:32)
306   >>> import sys
307   >>> sys.path.insert(0, '/tmp/example.zip')  # Add .zip file to front of path
308   >>> import jwzthreading
309   >>> jwzthreading.__file__
310   '/tmp/example.zip/jwzthreading.py'
311   >>>
312
313An entry in ``sys.path`` can now be the filename of a ZIP archive. The ZIP
325.. seealso::
326
327   :pep:`273` - Import Modules from Zip Archives
328      Written by James C. Ahlstrom,  who also provided an implementation. Python 2.3
329      follows the specification in :pep:`273`,  but uses an implementation written by
330      Just van Rossum  that uses the import hooks described in :pep:`302`. See section
331      :ref:`section-pep302` for a description of the new import hooks.
332
n333-.. % ======================================================================
n332+.. ======================================================================
334
335
336PEP 277: Unicode file name support for Windows NT
337=================================================
338
339On Windows NT, 2000, and XP, the system stores file names as Unicode strings.
340Traditionally, Python has represented file names as byte strings, which is
341inadequate because it renders some file names inaccessible.
359
360
361.. seealso::
362
363   :pep:`277` - Unicode file name support for Windows NT
364      Written by Neil Hodgson; implemented by Neil Hodgson, Martin von Löwis, and Mark
365      Hammond.
366
n367-.. % ======================================================================
n366+.. ======================================================================
368
369
370PEP 278: Universal Newline Support
371==================================
372
373The three major operating systems used today are Microsoft Windows, Apple's
374Macintosh OS, and the various Unix derivatives.  A minor irritation of cross-
375platform work  is that these three platforms all use different characters to
394:program:`configure` script.
395
396
397.. seealso::
398
399   :pep:`278` - Universal Newline Support
400      Written and implemented by Jack Jansen.
401
n402-.. % ======================================================================
n401+.. ======================================================================
403
404
405.. _section-enumerate:
406
407PEP 279: enumerate()
408====================
409
410A new built-in function, :func:`enumerate`, will make certain loops a bit
426       L[i] = result
427
428
429.. seealso::
430
431   :pep:`279` - The enumerate() built-in function
432      Written and implemented by Raymond D. Hettinger.
433
n434-.. % ======================================================================
n433+.. ======================================================================
435
436
437PEP 282: The logging Package
438============================
439
440A standard package for writing logs, :mod:`logging`, has been added to Python
4412.3.  It provides a powerful and flexible mechanism for generating logging
442output which can then be filtered and processed in various ways.  A
524can modify the record before passing it along.  When they're finally output,
525:class:`LogRecord` instances are converted to text by a :class:`Formatter`
526class.  All of these classes can be replaced by your own specially-written
527classes.
528
529With all of these features the :mod:`logging` package should provide enough
530flexibility for even the most complicated applications.  This is only an
531incomplete overview of its features, so please see the package's reference
n532-documentation (XXX reference: ../lib/module-logging.html) for all of the
533-details.  Reading :pep:`282` will also be helpful.
531+documentation for all of the details.  Reading :pep:`282` will also be helpful.
534
535
536.. seealso::
537
538   :pep:`282` - A Logging System
539      Written by Vinay Sajip and Trent Mick; implemented by Vinay Sajip.
540
n541-.. % ======================================================================
n539+.. ======================================================================
542
543
544.. _section-bool:
545
546PEP 285: A Boolean Type
547=======================
548
549A Boolean type was added to Python 2.3.  Two new constants were added to the
605instead of ``'1'`` and ``'0'``.
606
607
608.. seealso::
609
610   :pep:`285` - Adding a bool type
611      Written and implemented by GvR.
612
n613-.. % ======================================================================
n611+.. ======================================================================
614
615
616PEP 293: Codec Error Handling Callbacks
617=======================================
618
619When encoding a Unicode string into a byte string, unencodable characters may be
620encountered.  So far, Python has allowed specifying the error processing as
621either "strict" (raising :exc:`UnicodeError`), "ignore" (skipping the
637characters and "xmlcharrefreplace" emits XML character references.
638
639
640.. seealso::
641
642   :pep:`293` - Codec Error Handling Callbacks
643      Written and implemented by Walter Dörwald.
644
n645-.. % ======================================================================
n643+.. ======================================================================
646
647
648.. _section-pep301:
649
650PEP 301: Package Index and Metadata for Distutils
651=================================================
652
653Support for the long-requested Python catalog makes its first appearance in 2.3.
654
655The heart of the catalog is the new Distutils :command:`register` command.
656Running ``python setup.py register`` will collect the metadata describing a
657package, such as its name, version, maintainer, description, &c., and send it to
658a central catalog server.  The resulting catalog is available from
n659-`<http://www.python.org/pypi>`_.
n657+http://www.python.org/pypi.
660
661To make the catalog a bit more useful, a new optional *classifiers* keyword
662argument has been added to the Distutils :func:`setup` function.  A list of
663`Trove <http://catb.org/~esr/trove/>`_-style strings can be supplied to help
664classify the software.
665
666Here's an example :file:`setup.py` with classifiers, written to be compatible
667with older versions of the Distutils::
668
669   from distutils import core
670   kw = {'name': "Quixote",
671         'version': "0.5.1",
672         'description': "A highly Pythonic Web application framework",
673         # ...
674         }
675
n676-   if (hasattr(core, 'setup_keywords') and 
n674+   if (hasattr(core, 'setup_keywords') and
677       'classifiers' in core.setup_keywords):
678       kw['classifiers'] = \
679           ['Topic :: Internet :: WWW/HTTP :: Dynamic Content',
680            'Environment :: No Input/Output (Daemon)',
681            'Intended Audience :: Developers'],
682
683   core.setup(**kw)
684
686register --list-classifiers``.
687
688
689.. seealso::
690
691   :pep:`301` - Package Index and Metadata for Distutils
692      Written and implemented by Richard Jones.
693
n694-.. % ======================================================================
n692+.. ======================================================================
695
696
697.. _section-pep302:
698
699PEP 302: New Import Hooks
700=========================
701
702While it's been possible to write custom import hooks ever since the
752   raise ImportError
753
754
755.. seealso::
756
757   :pep:`302` - New Import Hooks
758      Written by Just van Rossum and Paul Moore. Implemented by Just van Rossum.
759
n760-.. % ======================================================================
n758+.. ======================================================================
761
762
763.. _section-pep305:
764
765PEP 305: Comma-separated Files
766==============================
767
768Comma-separated files are a format frequently used for exporting data from
798
799
800.. seealso::
801
802   :pep:`305` - CSV File API
803      Written and implemented  by Kevin Altis, Dave Cole, Andrew McNamara, Skip
804      Montanaro, Cliff Wells.
805
n806-.. % ======================================================================
n804+.. ======================================================================
807
808
n809-.. _section-pep305:
n807+.. _section-pep307:
810
811PEP 307: Pickle Enhancements
812============================
813
814The :mod:`pickle` and :mod:`cPickle` modules received some attention during the
8152.3 development cycle.  In 2.2, new-style classes could be pickled without
816difficulty, but they weren't pickled very compactly; :pep:`307` quotes a trivial
817example where a new-style class results in a pickled string three times longer
841codes for private use.  Currently no codes have been specified.
842
843
844.. seealso::
845
846   :pep:`307` - Extensions to the pickle protocol
847      Written and implemented  by Guido van Rossum and Tim Peters.
848
n849-.. % ======================================================================
n847+.. ======================================================================
850
851
852.. _section-slices:
853
854Extended Slices
855===============
856
857Ever since Python 1.4, the slicing syntax has supported an optional third "step"
951           else:
952               return self.calc_item(i)
953
954From this example you can also see that the built-in :class:`slice` object is
955now the type object for the slice type, and is no longer a function.  This is
956consistent with Python 2.2, where :class:`int`, :class:`str`, etc., underwent
957the same change.
958
n959-.. % ======================================================================
n957+.. ======================================================================
960
961
962Other Language Changes
963======================
964
965Here are all of the changes that Python 2.3 makes to the core Python language.
966
967* The :keyword:`yield` statement is now always a keyword, as described in
1024  all values set to *value*, defaulting to ``None``.
1025
1026  (Patches contributed by Raymond Hettinger.)
1027
1028  Also, the :func:`dict` constructor now accepts keyword arguments to simplify
1029  creating small dictionaries::
1030
1031     >>> dict(red=1, blue=2, green=3, black=4)
n1032-     {'blue': 2, 'black': 4, 'green': 3, 'red': 1}    
n1030+     {'blue': 2, 'black': 4, 'green': 3, 'red': 1}
1033
1034  (Contributed by Just van Rossum.)
1035
1036* The :keyword:`assert` statement no longer checks the ``__debug__`` flag, so
1037  you can no longer disable assertions by assigning to ``__debug__``. Running
1038  Python with the :option:`-O` switch will still generate code that doesn't
1039  execute any assertions.
1040
1041* Most type objects are now callable, so you can use them to create new objects
1042  such as functions, classes, and modules.  (This means that the :mod:`new` module
1043  can be deprecated in a future Python version, because you can now use the type
1044  objects available in the :mod:`types` module.) For example, you can create a new
1045  module object with the following code:
n1046- 
1047-  .. % XXX should new.py use PendingDeprecationWarning?
1048
1049  ::
1050
1051     >>> import types
1052     >>> m = types.ModuleType('abc','docstring')
1053     >>> m
1054     <module 'abc' (built-in)>
1055     >>> m.__doc__
1080  you'll only notice the difference if you have a really complicated inheritance
1081  hierarchy.  Classic classes are unaffected by this change.  Python 2.2
1082  originally used a topological sort of a class's ancestors, but 2.3 now uses the
1083  C3 algorithm as described in the paper `"A Monotonic Superclass Linearization
1084  for Dylan" <http://www.webcom.com/haahr/dylan/linearization-oopsla96.html>`_. To
1085  understand the motivation for this change,  read Michele Simionato's article
1086  `"Python 2.3 Method Resolution Order" <http://www.python.org/2.3/mro.html>`_, or
1087  read the thread on python-dev starting with the message at
n1088-  `<http://mail.python.org/pipermail/python-dev/2002-October/029035.html>`_.
n1084+  http://mail.python.org/pipermail/python-dev/2002-October/029035.html. Samuele
1089-  Samuele Pedroni first pointed out the problem and also implemented the fix by
1085+  Pedroni first pointed out the problem and also implemented the fix by coding the
1090-  coding the C3 algorithm.
1086+  C3 algorithm.
1091
1092* Python runs multithreaded programs by switching between threads after
1093  executing N bytecodes.  The default value for N has been increased from 10 to
1094  100 bytecodes, speeding up single-threaded applications by reducing the
1095  switching overhead.  Some multithreaded applications may suffer slower response
1096  time, but that's easily fixed by setting the limit back to a lower number using
1097  :func:`sys.setcheckinterval(N)`. The limit can be retrieved with the new
1098  :func:`sys.getcheckinterval` function.
1112     <type '_socket.socket'>
1113
1114* One of the noted incompatibilities between old- and new-style classes has been
1115  removed: you can now assign to the :attr:`__name__` and :attr:`__bases__`
1116  attributes of new-style classes.  There are some restrictions on what can be
1117  assigned to :attr:`__bases__` along the lines of those relating to assigning to
1118  an instance's :attr:`__class__` attribute.
1119
n1120-.. % ======================================================================
n1116+.. ======================================================================
1121
1122
1123String Changes
1124--------------
1125
1126* The :keyword:`in` operator now works differently for strings. Previously, when
1127  evaluating ``X in Y`` where *X* and *Y* are strings, *X* could only be a single
1128  character. That's now changed; *X* can be a string of any length, and ``X in Y``
1176  Unicode strings inherit from this type, so ``isinstance(obj, basestring)`` will
1177  return :const:`True` for either kind of string.  It's a completely abstract
1178  type, so you can't create :class:`basestring` instances.
1179
1180* Interned strings are no longer immortal and will now be garbage-collected in
1181  the usual way when the only reference to them is from the internal dictionary of
1182  interned strings.  (Implemented by Oren Tirosh.)
1183
n1184-.. % ======================================================================
n1180+.. ======================================================================
1185
1186
1187Optimizations
1188-------------
1189
1190* The creation of new-style class instances has been made much faster; they're
1191  now faster than classic classes!
1192
1208
1209* A number of small rearrangements have been made in various hotspots to improve
1210  performance, such as inlining a function or removing some code.  (Implemented
1211  mostly by GvR, but lots of people have contributed single changes.)
1212
1213The net result of the 2.3 optimizations is that Python 2.3 runs the  pystone
1214benchmark around 25% faster than Python 2.2.
1215
n1216-.. % ======================================================================
n1212+.. ======================================================================
1217
1218
1219New, Improved, and Deprecated Modules
1220=====================================
1221
1222As usual, Python's standard library received a number of enhancements and bug
1223fixes.  Here's a partial list of the most notable changes, sorted alphabetically
1224by module name. Consult the :file:`Misc/NEWS` file in the source tree for a more
1302
1303* The :mod:`gzip` module can now handle files exceeding 2 GiB.
1304
1305* The new :mod:`heapq` module contains an implementation of a heap queue
1306  algorithm.  A heap is an array-like data structure that keeps items in a
1307  partially sorted order such that, for every index *k*, ``heap[k] <=
1308  heap[2*k+1]`` and ``heap[k] <= heap[2*k+2]``.  This makes it quick to remove the
1309  smallest item, and inserting a new item while maintaining the heap property is
n1310-  O(lg n).  (See `<http://www.nist.gov/dads/HTML/priorityque.html>`_ for more
n1306+  O(lg n).  (See http://www.nist.gov/dads/HTML/priorityque.html for more
1311  information about the priority queue data structure.)
1312
1313  The :mod:`heapq` module provides :func:`heappush` and :func:`heappop` functions
1314  for adding and removing items while maintaining the heap property on top of some
1315  other mutable Python sequence type.  Here's an example that uses a Python list::
1316
1317     >>> import heapq
1318     >>> heap = []
1326     >>> heapq.heappop(heap)
1327     3
1328     >>> heap
1329     [5, 7, 11]
1330
1331  (Contributed by Kevin O'Connor.)
1332
1333* The IDLE integrated development environment has been updated using the code
n1334-  from the IDLEfork project (`<http://idlefork.sf.net>`_).  The most notable
n1330+  from the IDLEfork project (http://idlefork.sf.net).  The most notable feature is
1335-  feature is that the code being developed is now executed in a subprocess,
1331+  that the code being developed is now executed in a subprocess, meaning that
1336-  meaning that there's no longer any need for manual ``reload()`` operations.
1332+  there's no longer any need for manual ``reload()`` operations. IDLE's core code
1337-  IDLE's core code has been incorporated into the standard library as the
1333+  has been incorporated into the standard library as the :mod:`idlelib` package.
1338-  :mod:`idlelib` package.
1339
1340* The :mod:`imaplib` module now supports IMAP over SSL. (Contributed by Piers
1341  Lauder and Tino Lange.)
1342
1343* The :mod:`itertools` contains a number of useful functions for use with
1344  iterators, inspired by various functions provided by the ML and Haskell
1345  languages.  For example, ``itertools.ifilter(predicate, iterator)`` returns all
1346  elements in the iterator for which the function :func:`predicate` returns
1347  :const:`True`, and ``itertools.repeat(obj, N)`` returns ``obj`` *N* times.
1348  There are a number of other functions in the module; see the package's reference
n1349-  documentation (XXX reference: ../lib/module-itertools.html) for details.
n1344+  documentation for details.
1350  (Contributed by Raymond Hettinger.)
1351
1352* Two new functions in the :mod:`math` module, :func:`degrees(rads)` and
1353  :func:`radians(degs)`, convert between radians and degrees.  Other functions in
1354  the :mod:`math` module such as :func:`math.sin` and :func:`math.cos` have always
1355  required input values measured in radians.  Also, an optional *base* argument
1356  was added to :func:`math.log` to make it easier to compute logarithms for bases
1357  other than ``e`` and ``10``.  (Contributed by Raymond Hettinger.)
1502     will be now; if it be not now, yet
1503     it will come: the readiness is all.
1504     >>>
1505
1506  The module also contains a :class:`TextWrapper` class that actually implements
1507  the text wrapping strategy.   Both the :class:`TextWrapper` class and the
1508  :func:`wrap` and :func:`fill` functions support a number of additional keyword
1509  arguments for fine-tuning the formatting; consult the module's documentation
n1510-  (XXX reference: ../lib/module-textwrap.html) for details. (Contributed by Greg
n1505+  for details. (Contributed by Greg Ward.)
1511-  Ward.)
1512
1513* The :mod:`thread` and :mod:`threading` modules now have companion modules,
1514  :mod:`dummy_thread` and :mod:`dummy_threading`, that provide a do-nothing
1515  implementation of the :mod:`thread` module's interface for platforms where
1516  threads are not supported.  The intention is to simplify thread-aware modules
1517  (ones that *don't* rely on threads to run) by putting the following code at the
1518  top::
1519
1562* The :mod:`Tkinter` module now works with a thread-enabled  version of Tcl.
1563  Tcl's threading model requires that widgets only be accessed from the thread in
1564  which they're created; accesses from another thread can cause Tcl to panic.  For
1565  certain Tcl interfaces, :mod:`Tkinter` will now automatically avoid this  when a
1566  widget is accessed from a different thread by marshalling a command, passing it
1567  to the correct thread, and waiting for the results.  Other interfaces can't be
1568  handled automatically but :mod:`Tkinter` will now raise an exception on such an
1569  access so that you can at least find out about the problem.  See
n1570-  `<http://mail.python.org/pipermail/python-dev/2002-December/031107.html>`_ for a
n1564+  http://mail.python.org/pipermail/python-dev/2002-December/031107.html for a more
1571-  more detailed explanation of this change.  (Implemented by Martin von Löwis.)
1565+  detailed explanation of this change.  (Implemented by Martin von Löwis.)
1572- 
1573-  .. % 
1574
1575* Calling Tcl methods through :mod:`_tkinter` no longer  returns only strings.
1576  Instead, if Tcl returns other objects those objects are converted to their
1577  Python equivalent, if one exists, or wrapped with a :class:`_tkinter.Tcl_Obj`
1578  object if no Python equivalent exists. This behavior can be controlled through
1579  the :meth:`wantobjects` method of :class:`tkapp` objects.
1580
1581  When using :mod:`_tkinter` through the :mod:`Tkinter` module (as most Tkinter
1625     ...         try:
1626     ...             i = self.keylist.index(key)
1627     ...         except ValueError:
1628     ...             raise KeyError
1629     ...         self.keylist.pop(i)
1630     ...         self.valuelist.pop(i)
1631     ...     def keys(self):
1632     ...         return list(self.keylist)
n1633-     ... 
n1625+     ...
1634     >>> s = SeqDict()
1635     >>> dir(s)      # See that other dictionary methods are implemented
1636     ['__cmp__', '__contains__', '__delitem__', '__doc__', '__getitem__',
1637      '__init__', '__iter__', '__len__', '__module__', '__repr__',
1638      '__setitem__', 'clear', 'get', 'has_key', 'items', 'iteritems',
1639      'iterkeys', 'itervalues', 'keylist', 'keys', 'pop', 'popitem',
1640      'setdefault', 'update', 'valuelist', 'values']
1641
1659
1660* Support for internationalized domain names (RFCs 3454, 3490, 3491, and 3492)
1661  has been added. The "idna" encoding can be used to convert between a Unicode
1662  domain name and the ASCII-compatible encoding (ACE) of that name. ::
1663
1664     >{}>{}> u"www.Alliancefrançaise.nu".encode("idna")
1665     'www.xn--alliancefranaise-npb.nu'
1666
n1667-  The :mod:`socket` module has also been extended to transparently convert Unicode
n1659+  The :mod:`socket` module has also been extended to transparently convert
1668-  hostnames to the ACE version before passing them to the C library.  Modules that
1660+  Unicode hostnames to the ACE version before passing them to the C library.
1669-  deal with hostnames such as :mod:`httplib` and :mod:`ftplib`) also support
1661+  Modules that deal with hostnames such as :mod:`httplib` and :mod:`ftplib`)
1670-  Unicode host names; :mod:`httplib` also sends HTTP ``Host`` headers using the
1662+  also support Unicode host names; :mod:`httplib` also sends HTTP ``Host``
1671-  ACE version of the domain name.  :mod:`urllib` supports Unicode URLs with non-
1663+  headers using the ACE version of the domain name.  :mod:`urllib` supports
1672-  ASCII host names as long as the ``path`` part of the URL is ASCII only.
1664+  Unicode URLs with non-ASCII host names as long as the ``path`` part of the URL
1665+  is ASCII only.
1673
1674  To implement this change, the :mod:`stringprep` module, the  ``mkstringprep``
1675  tool and the ``punycode`` encoding have been added.
1676
n1677-.. % ======================================================================
n1670+.. ======================================================================
1678
1679
1680Date/Time Type
1681--------------
1682
1683Date and time types suitable for expressing timestamps were added as the
1684:mod:`datetime` module.  The types don't support different calendars or many
1685fancy features, and just stick to the basics of representing time.
1721
1722Instances can be compared, hashed, and converted to strings (the result is the
1723same as that of :meth:`isoformat`).  :class:`date` and :class:`datetime`
1724instances can be subtracted from each other, and added to :class:`timedelta`
1725instances.  The largest missing feature is that there's no standard library
1726support for parsing strings and getting back a :class:`date` or
1727:class:`datetime`.
1728
n1729-For more information, refer to the module's reference documentation (XXX
n1722+For more information, refer to the module's reference documentation.
1730-reference: ../lib/module-datetime.html). (Contributed by Tim Peters.)
1723+(Contributed by Tim Peters.)
1731
n1732-.. % ======================================================================
n1725+.. ======================================================================
1733
1734
1735The optparse Module
1736-------------------
1737
1738The :mod:`getopt` module provides simple parsing of command-line arguments.  The
1739new :mod:`optparse` module (originally named Optik) provides more elaborate
1740command-line parsing that follows the Unix conventions, automatically creates
1781   usage: opt.py [options]
1782
1783   options:
1784     -h, --help            show this help message and exit
1785     -iINPUT, --input=INPUT
1786                           set input filename
1787     -lLENGTH, --length=LENGTH
1788                           set maximum length of output
n1789-   $ 
n1782+   $
1790
n1791-See the module's documentation (XXX reference: ../lib/module-optparse.html) for
n1784+See the module's documentation for more details.
1792-more details.
1793
n1794-.. % $ prevent Emacs tex-mode from getting confused
1795
1796Optik was written by Greg Ward, with suggestions from the readers of the Getopt
1797SIG.
1798
n1799-.. % ======================================================================
n1790+.. ======================================================================
1800
1801
1802.. _section-pymalloc:
1803
1804Pymalloc: A Specialized Object Allocator
1805========================================
1806
1807Pymalloc, a specialized object allocator written by Vladimir Marangozov, was a
1864
1865.. seealso::
1866
1867   http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Objects/obmalloc.c
1868      For the full details of the pymalloc implementation, see the comments at the top
1869      of the file :file:`Objects/obmalloc.c` in the Python source code.  The above
1870      link points to the file within the SourceForge CVS browser.
1871
n1872-.. % ======================================================================
n1863+.. ======================================================================
1873
1874
1875Build and C API Changes
1876=======================
1877
1878Changes to Python's build process and to the C API include:
1879
1880* The cycle detection implementation used by the garbage collection has proven
1926
1927* If you dynamically allocate type objects in your extension, you should be
1928  aware of a change in the rules relating to the :attr:`__module__` and
1929  :attr:`__name__` attributes.  In summary, you will want to ensure the type's
1930  dictionary contains a ``'__module__'`` key; making the module name the part of
1931  the type name leading up to the final period will no longer have the desired
1932  effect.  For more detail, read the API reference documentation or the  source.
1933
n1934-.. % ======================================================================
n1925+.. ======================================================================
1935
1936
1937Port-Specific Changes
1938---------------------
1939
1940Support for a port to IBM's OS/2 using the EMX runtime environment was merged
1941into the main Python source tree.  EMX is a POSIX emulation layer over the OS/2
1942system APIs.  The Python port for EMX tries to support all the POSIX-like
1950compatibility.  This means that modules will no longer fail to load if a single
1951routine is missing on the current OS version. Instead calling the missing
1952routine will raise an exception. (Contributed by Jack Jansen.)
1953
1954The RPM spec files, found in the :file:`Misc/RPM/` directory in the Python
1955source distribution, were updated for 2.3.  (Contributed by Sean Reifschneider.)
1956
1957Other new platforms now supported by Python include AtheOS
n1958-(`<http://www.atheos.cx/>`_), GNU/Hurd, and OpenVMS.
n1949+(http://www.atheos.cx/), GNU/Hurd, and OpenVMS.
1959
n1960-.. % ======================================================================
n1951+.. ======================================================================
1961
1962
1963.. _section-other:
1964
1965Other Changes and Fixes
1966=======================
1967
1968As usual, there were a bunch of other improvements and bugfixes scattered
2003  added effect of making the code work as desired under "python -O" in earlier
2004  versions of Python.
2005
2006  A nifty new feature is that trace functions can now assign to the
2007  :attr:`f_lineno` attribute of frame objects, changing the line that will be
2008  executed next.  A ``jump`` command has been added to the :mod:`pdb` debugger
2009  taking advantage of this new feature. (Implemented by Richie Hindle.)
2010
n2011-.. % ======================================================================
n2002+.. ======================================================================
2012
2013
2014Porting to Python 2.3
2015=====================
2016
2017This section lists previously described changes that may require changes to your
2018code:
2019
2042
2043  There are a few ways to fix this warning.  If you really need a positive number,
2044  just add an ``L`` to the end of the literal.  If you're trying to get a 32-bit
2045  integer with low bits set and have previously used an expression such as ``~(1
2046  << 31)``, it's probably clearest to start with all bits set and clear the
2047  desired upper bits. For example, to clear just the top bit (bit 31), you could
2048  write ``0xffffffffL &~(1L<<31)``.
2049
n2050-  .. % The empty groups below prevent conversion to guillemets.
2051- 
2052* You can no longer disable assertions by assigning to ``__debug__``.
2053
2054* The Distutils :func:`setup` function has gained various new keyword arguments
2055  such as *depends*.  Old versions of the Distutils will abort if passed unknown
2056  keywords.  A solution is to check for the presence of the new
2057  :func:`get_distutil_options` function in your :file:`setup.py` and only uses the
2058  new keywords with a version of the Distutils that supports them::
2059
2065     ext = Extension(**kw)
2066
2067* Using ``None`` as a variable name will now result in a :exc:`SyntaxWarning`
2068  warning.
2069
2070* Names of extension types defined by the modules included with Python now
2071  contain the module and a ``'.'`` in front of the type name.
2072
n2073-.. % ======================================================================
n2062+.. ======================================================================
2074
2075
t2076-.. _acks:
t2065+.. _23acks:
2077
2078Acknowledgements
2079================
2080
2081The author would like to thank the following people for offering suggestions,
2082corrections and assistance with various drafts of this article: Jeff Bauer,
2083Simon Brunning, Brett Cannon, Michael Chermside, Andrew Dalke, Scott David
2084Daniels, Fred L. Drake, Jr., David Fraser,  Kelly Gerber, Raymond Hettinger,
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op