Commit daf4db21 authored by Raymond Hettinger's avatar Raymond Hettinger

More updates to whatsnew3.2

parent 5497a0a4
...@@ -53,22 +53,18 @@ This article explains the new features in Python 3.2, compared to 3.1. ...@@ -53,22 +53,18 @@ This article explains the new features in Python 3.2, compared to 3.1.
PEP 391: Dictionary Based Configuration for Logging PEP 391: Dictionary Based Configuration for Logging
==================================================== ====================================================
The :mod:`logging` module had two ways of configuring the module, either by calling The :mod:`logging` module provided two kinds of configuration, one style with
functions for each option or by reading an external file saved in a :mod:`ConfigParser` function calls for each option or another style driven by an external file saved
format. Those options did not provide the flexibility to create configurations in a :mod:`ConfigParser` format. Those options did not provide the flexibility
from JSON or YAML files and they did not support incremental configuration, which to create configurations from JSON or YAML files, nor they did not support
is needed for specifying logger options from a command line. incremental configuration, which is needed for specifying logger options from a
command line.
To support a more flexible style, the module now offers To support a more flexible style, the module now offers
:func:`logging.config.dictConfig` to use dictionaries to specify logger :func:`logging.config.dictConfig` for specifying logging configuration with
configuration (including formatters, handlers, filters, and loggers). For plain Python dictionaries. The configuration options include formatters,
example: handlers, filters, and loggers. Here's a working example of a configuration
dictionary::
>>> import logging.config
>>> logging.config.dictConfig(json.load(open('log.cfg', 'rb')))
The above fragment configures logging from a JSON-encoded dictionary stored in a
file called "log.cfg". Here's a working example of a configuration dictionary::
{"version": 1, {"version": 1,
"formatters": {"brief": {"format": "%(levelname)-8s: %(name)-15s: %(message)s"}, "formatters": {"brief": {"format": "%(levelname)-8s: %(name)-15s: %(message)s"},
...@@ -87,6 +83,15 @@ file called "log.cfg". Here's a working example of a configuration dictionary:: ...@@ -87,6 +83,15 @@ file called "log.cfg". Here's a working example of a configuration dictionary::
}, },
"root": {"level": "DEBUG", "handlers": ["console", "console_priority"]}} "root": {"level": "DEBUG", "handlers": ["console", "console_priority"]}}
If that dictionary is stored in a file called "conf.json", it can loaded
and called with code like this::
>>> import logging.config
>>> logging.config.dictConfig(json.load(open('conf.json', 'rb')))
>>> logging.info("Transaction completed normally")
>>> logging.critical("Abnormal termination")
.. seealso:: .. seealso::
:pep:`391` - Dictionary Based Configuration for Logging :pep:`391` - Dictionary Based Configuration for Logging
...@@ -218,8 +223,22 @@ Some smaller changes made to the core Python language are: ...@@ -218,8 +223,22 @@ Some smaller changes made to the core Python language are:
* The :mod:`abc` module now supports :func:`~abc.abstractclassmethod` and * The :mod:`abc` module now supports :func:`~abc.abstractclassmethod` and
:func:`~abc.abstractstaticmethod`. :func:`~abc.abstractstaticmethod`.
(:issue:`5867`.) (Patch submitted by Daniel Urban; :issue:`5867`.)
* A warning message will now get printed at interpreter shutdown if the
:data:`gc.garbage` list isn't empty. This is meant to make the programmer
aware that their code contains object finalization issues.
(Added by Antoine Pitrou; :issue:`477863`.)
* Mark Dickinson crafted an elegant and efficient scheme for assuring that
different numeric datatypes will have the same hash value whenever their
actual values are equal::
>>> assert hash(Fraction(3, 2)) == hash(1.5) == \
hash(Decimal("1.5")) == hash(complex(1.5, 0))
(See :issue:`8188`.)
New, Improved, and Deprecated Modules New, Improved, and Deprecated Modules
===================================== =====================================
...@@ -263,7 +282,7 @@ New, Improved, and Deprecated Modules ...@@ -263,7 +282,7 @@ New, Improved, and Deprecated Modules
* The :class:`ftplib.FTP` class now supports the context manager protocol to * The :class:`ftplib.FTP` class now supports the context manager protocol to
unconditionally consume :exc:`socket.error` exceptions and to close the FTP unconditionally consume :exc:`socket.error` exceptions and to close the FTP
connection when done: connection when done::
>>> from ftplib import FTP >>> from ftplib import FTP
>>> with FTP("ftp1.at.proftpd.org") as ftp: >>> with FTP("ftp1.at.proftpd.org") as ftp:
...@@ -276,13 +295,15 @@ New, Improved, and Deprecated Modules ...@@ -276,13 +295,15 @@ New, Improved, and Deprecated Modules
dr-xr-xr-x 5 ftp ftp 4096 May 6 10:43 CentOS dr-xr-xr-x 5 ftp ftp 4096 May 6 10:43 CentOS
dr-xr-xr-x 3 ftp ftp 18 Jul 10 2008 Fedora dr-xr-xr-x 3 ftp ftp 18 Jul 10 2008 Fedora
(Contributed by Tarek Ziadé and Giampaolo Rodolà; :issue:`4972`.) Other file-like objects such as :class:`mmap.mmap` and :func:`fileinput.input`
also grew auto-closing context managers::
* A warning message will now get printed at interpreter shutdown if the with fileinput.input(files=('log1.txt', 'log2.txt')) as f:
:data:`gc.garbage` list isn't empty. This is meant to make the programmer for line in f:
aware that their code contains object finalization issues. process(line)
(Added by Antoine Pitrou; :issue:`477863`.) (Contributed by Tarek Ziadé and Giampaolo Rodolà in :issue:`4972`, and
by Georg Brandl in :issue:`8046` and :issue:`1286`.)
* The :mod:`os` module now has the :const:`ST_RDONLY` and :const:`ST_NOSUID` * The :mod:`os` module now has the :const:`ST_RDONLY` and :const:`ST_NOSUID`
constants, for use with the :func:`~os.statvfs` function. constants, for use with the :func:`~os.statvfs` function.
...@@ -395,15 +416,39 @@ Multi-threading ...@@ -395,15 +416,39 @@ Multi-threading
argument. (Contributed by Torsten Landschoff; :issue:`850728`.) argument. (Contributed by Torsten Landschoff; :issue:`850728`.)
.. Optimizations Optimizations
============= =============
Major performance enhancements have been added: A number of small performance enhancements have been added:
* Stub * JSON decoding performance is improved and memory consumption is reduced
whenever the same string is repeated for multiple keys.
(Contributed by Antoine Pitrou; :issue:`7451`.)
- Python's peephole optimizer now recognizes patterns such ``x in {1, 2, 3}`` as
being a test for membership in a set of constants. The optimizer recasts the
:class:`set` as a :class:`frozenset` and stores the pre-built constant.
Now that the speed penalty is gone, it is practical to start writing
membership tests using set-notation. This style is both semantically clear
and operationally fast::
extension = name.rpartition('.')[2]
if extension in {'xml', 'html', 'xhtml', 'css'}:
handle(name)
(Patch and additional tests by Dave Malcolm; :issue:`6690`).
* The fast-search algorithm in stringlib is now used by the :meth:`split`,
:meth:`rsplit`, :meth:`splitlines` and :meth:`replace` methods on
:class:`bytes`, :class:`bytearray` and :class:`str` objects. Likewise, the
algorithm is also used by :meth:`rfind`, :meth:`rindex`, :meth:`rsplit` and
:meth:`rpartition`.
(Patch by Florent Xicluna in :issue:`7622` and :issue:`7462`.)
Filenames and unicode Filenames and Unicode
===================== =====================
The filesystem encoding can be specified by setting the The filesystem encoding can be specified by setting the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment