:meth:`~logging.Logger.debug`, etc.), now accept exception instances
in ``exc_info`` parameter, in addition to boolean values and exception
tuples. (Contributed by Yury Selivanov in :issue:`20537`.)
:class:`~logging.handlers.HTTPHandler` now accepts an optional
:class:`ssl.SSLContext` instance to configure the SSL settings used
in an HTTP connection. (Contributed by Alex Gaynor in :issue:`22788`.)
* :class:`~logging.handlers.HTTPHandler` now accepts optional
:class:`ssl.SSLContext` instance to configure the SSL settings used
for HTTP connection.
(Contributed by Alex Gaynor in :issue:`22788`.)
:class:`~logging.handlers.QueueListener` now takes a *respect_handler_level*
keyword argument which, if set to ``True``, will pass messages to handlers
taking handler levels into account. (Contributed by Vinay Sajip.)
* :class:`~logging.handlers.QueueListener` now takes a *respect_handler_level*
keyword argument which, if set to ``True``, will pass messages to handlers
taking handler levels into account. (Contributed by Vinay Sajip.)
lzma
----
* New option *max_length* for :meth:`~lzma.LZMADecompressor.decompress`
to limit the maximum size of decompressed data.
(Contributed by Martin Panter in :issue:`15955`.)
:meth:`~lzma.LZMADecompressor.decompress` now accepts an optional *max_length*
argument to limit the maximum size of decompressed data.
(Contributed by Martin Panter in :issue:`15955`.)
math
----
* :data:`math.inf` and :data:`math.nan` constants added. (Contributed by Mark
Dickinson in :issue:`23185`.)
Two new constants have been added to :mod:`math`: :data:`math.inf`
and :data:`math.nan`. (Contributed by Mark Dickinson in :issue:`23185`.)
* New :func:`~math.isclose` function.
(Contributed by Chris Barker and Tal Einat in :issue:`24270`.)
A new function :func:`math.isclose` provides a way to test for approximate
equality. (Contributed by Chris Barker and Tal Einat in :issue:`24270`.)
A new :func:`~math.gcd` function has been added. The :func:`fractions.gcd`
function is now deprecated. (Contributed by Mark Dickinson and Serhiy
Storchaka in :issue:`22486`.)
* New :func:`~math.gcd` function. The :func:`fractions.gcd` function now is
deprecated.
(Contributed by Mark Dickinson and Serhiy Storchaka in :issue:`22486`.)
operator
--------
* :func:`~operator.attrgetter`, :func:`~operator.itemgetter`, and
:func:`~operator.methodcaller` objects now support pickling.
(Contributed by Josh Rosenberg and Serhiy Storchaka in :issue:`22955`.)
:func:`~operator.attrgetter`, :func:`~operator.itemgetter`, and
:func:`~operator.methodcaller` objects now support pickling.
(Contributed by Josh Rosenberg and Serhiy Storchaka in :issue:`22955`.)
os
--
* New :func:`os.scandir` function that exposes file information from
the operating system when listing a directory. :func:`os.scandir`
returns an iterator of :class:`os.DirEntry` objects corresponding to
the entries in the directory given by *path*. (Contributed by Ben
Hoyt with the help of Victor Stinner in :issue:`22524`.)
The new :func:`os.scandir` returning an iterator of :class:`os.DirEntry`
objects has been added. If possible, :func:`os.scandir` extracts file
attributes while scanning a directory, removing the need to perform
subsequent system calls to determine file type or attributes, which may
significantly improve performance. (Contributed by Ben Hoyt with the help
of Victor Stinner in :issue:`22524`.)
On Windows, a new :attr:`~os.stat_result.st_file_attributes` attribute is
now available. It corresponds to ``dwFileAttributes`` member of the
``BY_HANDLE_FILE_INFORMATION`` structure returned by
``GetFileInformationByHandle()``. (Contributed by Ben Hoyt in :issue:`21719`.)
* :class:`os.stat_result` now has a :attr:`~os.stat_result.st_file_attributes`
attribute on Windows. (Contributed by Ben Hoyt in :issue:`21719`.)
:func:`os.urandom` now uses ``getrandom()`` syscall on Linux 3.17 or newer,
and ``getentropy()`` on OpenBSD 5.6 and newer, removing the need to use
``/dev/urandom`` and avoiding failures due to potential file descriptor
exhaustion. (Contributed by Victor Stinner in :issue:`22181`.)
* :func:`os.urandom`: On Linux 3.17 and newer, the ``getrandom()`` syscall is
now used when available. On OpenBSD 5.6 and newer, the C ``getentropy()``
function is now used. These functions avoid the usage of an internal file
descriptor.
(Contributed by Victor Stinner in :issue:`22181`.)
New :func:`os.get_blocking` and :func:`os.set_blocking` functions allow to
get and set the file descriptor blocking mode (:data:`~os.O_NONBLOCK`.)
(Contributed by Victor Stinner in :issue:`22054`.)
* New :func:`os.get_blocking` and :func:`os.set_blocking` functions to
get and set the blocking mode of file descriptors.
(Contributed by Victor Stinner in :issue:`22054`.)
:func:`~os.truncate` and :func:`~os.ftruncate` are now supported on
Windows. (Contributed by Steve Dower in :issue:`23668`.)
* :func:`~os.truncate` and :func:`~os.ftruncate` are now supported on
Windows. (Contributed by Steve Dower in :issue:`23668`.)
os.path
-------
* New :func:`~os.path.commonpath` function that extracts common path prefix.
Unlike the :func:`~os.path.commonprefix` function, it always returns a valid
path. (Contributed by Rafik Draoui and Serhiy Storchaka in :issue:`10395`.)
There is a new :func:`~os.path.commonpath` function returning the longest
common sub-path of each passed pathname. Unlike the
:func:`~os.path.commonprefix` function, it always returns a valid
path. (Contributed by Rafik Draoui and Serhiy Storchaka in :issue:`10395`.)
pathlib
-------
* New :meth:`~pathlib.Path.samefile` method to check if other path object
points to the same file. (Contributed by Vajrasky Kok and Antoine Pitrou
in :issue:`19775`.)
The new :meth:`~pathlib.Path.samefile` method can be used to check if the
passed :class:`~pathlib.Path` object, or a string, point to the same file as
the :class:`~pathlib.Path` on which :meth:`~pathlib.Path.samefile` is called.
(Contributed by Vajrasky Kok and Antoine Pitrou in :issue:`19775`.)
:meth:`~pathlib.Path.mkdir` how accepts a new optional ``exist_ok`` argument
to match ``mkdir -p`` and :func:`os.makrdirs` functionality.
(Contributed by Berker Peksag in :issue:`21539`.)
* :meth:`~pathlib.Path.mkdir` has a new optional parameter ``exist_ok``
to mimic ``mkdir -p`` and :func:`os.makrdirs` functionality.
(Contributed by Berker Peksag in :issue:`21539`.)
There is a new :meth:`~pathlib.Path.expanduser` method to expand ``~``
and ``~user`` prefixes. (Contributed by Serhiy Storchaka and Claudiu
Popa in :issue:`19776`.)
* New :meth:`~pathlib.Path.expanduser` to expand ``~`` and ``~user``
constructs.
(Contributed by Serhiy Storchaka and Claudiu Popa in :issue:`19776`.)
A new :meth:`~pathlib.Path.home` class method can be used to get an instance
of :class:`~pathlib.Path` object representing the user’s home directory.
(Contributed by Victor Salgado and Mayank Tripathi in :issue:`19777`.)
* New class method :meth:`~pathlib.Path.home` to get an instance of
:class:`~pathlib.Path` object representing the user’s home directory.
(Contributed by Victor Salgado and Mayank Tripathi in :issue:`19777`.)
pickle
------
* Serializing more "lookupable" objects (such as unbound methods or nested
classes) now are supported with pickle protocols < 4.
(Contributed by Serhiy Storchaka in :issue:`23611`.)
Nested objects, such as unbound methods or nested classes, can now be pickled using :ref:`pickle protocols <pickle-protocols>` older than protocol version 4,
which already supported these cases. (Contributed by Serhiy Storchaka in
:issue:`23611`.)
poplib
------
* A new command :meth:`~poplib.POP3.utf8` enables :rfc:`6856`
(internationalized email) support if the POP server supports it. (Contributed
by Milan OberKirch in :issue:`21804`.)
A new command :meth:`~poplib.POP3.utf8` enables :rfc:`6856`
(internationalized email) support, if the POP server supports it.
(Contributed by Milan OberKirch in :issue:`21804`.)
re
--
* Number of capturing groups in regular expression is no longer limited by 100.
(Contributed by Serhiy Storchaka in :issue:`22437`.)
The number of capturing groups in regular expression is no longer limited by
100. (Contributed by Serhiy Storchaka in :issue:`22437`.)
:func:`re.sub` and :func:`re.subn` now replace unmatched groups with empty
strings instead of rising an exception. (Contributed by Serhiy Storchaka
in :issue:`1519638`.)
* Now unmatched groups are replaced with empty strings in :func:`re.sub`
and :func:`re.subn`. (Contributed by Serhiy Storchaka in :issue:`1519638`.)
readline
--------
* New :func:`~readline.append_history_file` function.
(Contributed by Bruno Cauet in :issue:`22940`.)
The new :func:`~readline.append_history_file` function can be used to append
the specified number of trailing elements in history to a given file.
(Contributed by Bruno Cauet in :issue:`22940`.)
shutil
------
* :func:`~shutil.move` now accepts a *copy_function* argument, allowing,
for example, :func:`~shutil.copy` to be used instead of the default
:func:`~shutil.copy2` if there is a need to ignore metadata. (Contributed by
Claudiu Popa in :issue:`19840`.)
:func:`~shutil.move` now accepts a *copy_function* argument, allowing,
for example, :func:`~shutil.copy` to be used instead of the default
:func:`~shutil.copy2` there is a need to ignore file metadata when moving.
(Contributed by Claudiu Popa in :issue:`19840`.)
:func:`~shutil.make_archive` now supports *xztar* format.
(Contributed by Serhiy Storchaka in :issue:`5411`.)
* :func:`~shutil.make_archive` now supports *xztar* format.
(Contributed by Serhiy Storchaka in :issue:`5411`.)
signal
------
* On Windows, :func:`signal.set_wakeup_fd` now also supports socket handles.
(Contributed by Victor Stinner in :issue:`22018`.)
On Windows, :func:`signal.set_wakeup_fd` now also supports socket handles.
(Contributed by Victor Stinner in :issue:`22018`.)
Various ``SIG*`` constants in :mod:`signal` module have been converted into
:mod:`Enums <enum>`. This allows meaningful names to be printed
during debugging, instead of integer "magic numbers".
(Contributed by Giampaolo Rodola'in:issue:`21076`.)
* Different constants of :mod:`signal` module are now enumeration values using
the :mod:`enum` module. This allows meaningful names to be printed during
debugging, instead of integer “magic numbers”. (Contributed by Giampaolo
Rodola' in :issue:`21076`.)
smtpd
-----
* Both :class:`~smtpd.SMTPServer` and :class:`smtpd.SMTPChannel` now accept a
*decode_data* keyword to determine if the DATA portion of the SMTP
transaction is decoded using the ``utf-8`` codec or is instead provided to
:meth:`~smtpd.SMTPServer.process_message` as a byte string. The default
is ``True`` for backward compatibility reasons, but will change to ``False``
in Python 3.6. If *decode_data* is set to ``False``, the
:meth:`~smtpd.SMTPServer.process_message` method must be prepared to accept
keyword arguments. (Contributed by Maciej Szulik in :issue:`19662`.)
* :class:`~smtpd.SMTPServer` now advertises the ``8BITMIME`` extension
(:rfc:`6152`) if if *decode_data* has been set ``True``. If the client
specifies ``BODY=8BITMIME`` on the ``MAIL`` command, it is passed to
:meth:`~smtpd.SMTPServer.process_message` via the ``mail_options`` keyword.
(Contributed by Milan Oberkirch and R. David Murray in :issue:`21795`.)
* :class:`~smtpd.SMTPServer` now supports the ``SMTPUTF8`` extension
(:rfc:`6531`: Internationalized Email). If the client specified ``SMTPUTF8
BODY=8BITMIME`` on the ``MAIL`` command, they are passed to
:meth:`~smtpd.SMTPServer.process_message` via the ``mail_options`` keyword.
It is the responsibility of the :meth:`~smtpd.SMTPServer.process_message`
method to correctly handle the ``SMTPUTF8`` data. (Contributed by Milan
Oberkirch in :issue:`21725`.)
* It is now possible to provide, directly or via name resolution, IPv6
addresses in the :class:`~smtpd.SMTPServer` constructor, and have it
successfully connect. (Contributed by Milan Oberkirch in :issue:`14758`.)