diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst index e3a92d1956b..b2dc01fa7db 100644 --- a/Doc/whatsnew/3.2.rst +++ b/Doc/whatsnew/3.2.rst @@ -530,6 +530,11 @@ The biggest news for Python 3.2 is that the :mod:`email` package and :mod:`nntplib` modules now work correctly with the bytes/text model in Python 3. For the first time, there is correct handling of inputs with mixed encodings. +Throughout the standard library, there has been more careful attention to +encodings and text versus bytes issues. In particular, interactions with the +operating system are now better able to pass non-ASCII data using the Windows +mcbs encoding, locale aware encodings, or UTF-8. + Another significant win is the addition of substantially better support for *SSL* connections and security certificates. @@ -576,6 +581,39 @@ format. (Proposed and implemented by R. David Murray, :issue:`4661` and :issue:`10321`.) +elementtree +----------- + +The :mod:`xml.etree.ElementTree` package and it's :mod:`xml.etree.cElementTree` +counterpart have been updated to version 1.3. + +Several new and useful functions and methods have been added: + +* :func:`xml.etree.ElementTree.fromstringlist` which builds an XML document + from a sequence of fragments +* :func:`xml.etree.ElementTree.register_namespace` for registering a global + namespace prefix +* :func:`xml.etree.ElementTree.tostringlist` for string representation + including all sublists +* :meth:`xml.etree.ElementTree.Element.extend` for appending a sequence of zero + or more elements +* :meth:`xml.etree.ElementTree.Element.iterfind` searches an element and + subelements +* :meth:`xml.etree.ElementTree.Element.itertext` creates a text iterator over + an element and its sub-elements +* :meth:`xml.etree.ElementTree.TreeBuilder.end` closes the current element +* :meth:`xml.etree.ElementTree.TreeBuilder.doctype` handles a doctype + declaration + +Two methods have been deprecated: + +* :meth:`xml.etree.ElementTree.getchildren` use ``list(elem)`` instead. +* :meth:`xml.etree.ElementTree.getiterator` use ``Element.iter`` instead. + +For details of the update, see `Introducing ElementTree +`_ on Fredrik Lundh's website. + +(Contributed by Fredrik Lundh.) functools --------- @@ -619,6 +657,36 @@ functools (By Nick Coghlan and Terrence Cole; :issue:`9567`, :issue:`3445`, and :issue:`8814`.) +* To help write classes with rich comparison methods, a new decorator + :func:`functools.total_ordering` will use a existing equality and inequality + methods to fill-in the remaining methods. + + For example, supplying *__eq__* and *__lt__* will enable + :func:`~functools.total_ordering` to fill-in *__le__*, *__gt__* and *__ge__*:: + + @total_ordering + class Student: + def __eq__(self, other): + return ((self.lastname.lower(), self.firstname.lower()) == + (other.lastname.lower(), other.firstname.lower())) + def __lt__(self, other): + return ((self.lastname.lower(), self.firstname.lower()) < + (other.lastname.lower(), other.firstname.lower())) + + (Contributed by Raymond Hettinger.) + +* To aid in porting programs from Python 2, the :func:`~functools.cmp_to_key` + function converts an old-style comparion function to + modern :term:`key function`: + + >>> # locale-aware sort order + >>> sorted(iterable, key=cmp_to_key(locale.strcoll)) + + For sorting examples and a brief sorting tutorial, see the `Sorting HowTo + `_ tutorial. + + (Contributed by Raymond Hettinger.) + itertools --------- @@ -677,6 +745,21 @@ collections >>> list(d) ['X', 'a', 'b', 'd', 'e'] + (Contributed by Raymond Hettinger.) + +* The :class:`collections.deque` grew two new methods :meth:`~collections.deque.count` + and :meth:`collections.deque.reverse` that make them more substitutable for + :class:`list` when needed: + + >>> d = deque('simsalabim') + >>> d.count('s') + 2 + >>> d.reverse() + >>> d + deque(['m', 'i', 'b', 'a', 'l', 'a', 's', 'm', 'i', 's']) + + (Contributed by Raymond Hettinger.) + datetime -------- @@ -785,22 +868,27 @@ the constructor and to support mixed-type comparisons. * The :class:`decimal.Decimal` contructor now accepts :class:`float` objects directly so there in no longer a need to use the :meth:`~decimal.Decimal.from_float` - method. + method (:issue:`8257`). * Mixed type comparisons are now fully supported so that :class:`~decimal.Decimal` objects can be directly compared with :class:`float` - and :class:`fractions.Fraction`. + and :class:`fractions.Fraction` (:issue:`2531` and :issue:`8188`). Similar changes were made to :class:`fractions.Fraction` so that the :meth:`~fractions.Fraction.from_float()` and :meth:`~fractions.Fraction.from_decimal` -methods are no longer needed. +methods are no longer needed (:issue:`8294`): + +>>> Decimal(1.1) +Decimal('1.100000000000000088817841970012523233890533447265625') +>>> Fraction(1.1) +Fraction(2476979795053773, 2251799813685248) Another useful change for the :mod:`decimal` module is that the :attr:`Context.clamp` attribute is now public. This is useful in creating contexts that correspond to the decimal interchange formats specified in IEEE 754 (see :issue:`8540`). -(Contributed by Mark Dickinson.) +(Contributed by Mark Dickinson and Raymond Hettinger.) ftp --- @@ -832,8 +920,8 @@ by Georg Brandl in :issue:`8046` and :issue:`1286`.) .. XXX mention os.popen and subprocess.Popen auto-closing of fds -gzip ----- +gzip and zipfile +---------------- :class:`gzip.GzipFile` now implements the :class:`io.BufferedIOBase` :term:`abstract base class` (except for ``truncate()``). It also has a @@ -860,6 +948,14 @@ before compressing and decompressing: Aides and Brian Curtin in :issue:`9962`, :issue:`1675951`, :issue:`7471` and :issue:`2846`.) +Also, the :class:`zipfile.ZipExtFile` class was reworked internally to represent +files stored inside an archive. The new implementation is significantly faster +and can be wrapped in a :class:`io.BufferedReader` object for more speedups. It +also solves an issue where interleaved calls to *read* and *readline* gave the +wrong results. + +(Patch submitted by by Nir Aides in :issue:`7610`.) + shutil ------ @@ -877,7 +973,7 @@ The :func:`shutil.copytree` function has two new options: sqlite3 ------- -The :mod:`sqlite3` module has two new capabilities. +The :mod:`sqlite3` module was updated to version 2.6.0. It has two new capabilities. * The :attr:`sqlite3.Connection.in_transit` attribute is true if there is an active transaction for uncommitted changes.