2527 lines
306 KiB
HTML
2527 lines
306 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<title>What’s New In Python 3.3 — Python 3.7.4 documentation</title>
|
||
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||
|
||
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
|
||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
||
<script type="text/javascript" src="../_static/language_data.js"></script>
|
||
|
||
<script type="text/javascript" src="../_static/sidebar.js"></script>
|
||
|
||
<link rel="search" type="application/opensearchdescription+xml"
|
||
title="Search within Python 3.7.4 documentation"
|
||
href="../_static/opensearch.xml"/>
|
||
<link rel="author" title="About these documents" href="../about.html" />
|
||
<link rel="index" title="Index" href="../genindex.html" />
|
||
<link rel="search" title="Search" href="../search.html" />
|
||
<link rel="copyright" title="Copyright" href="../copyright.html" />
|
||
<link rel="next" title="What’s New In Python 3.2" href="3.2.html" />
|
||
<link rel="prev" title="What’s New In Python 3.4" href="3.4.html" />
|
||
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
|
||
<link rel="canonical" href="https://docs.python.org/3/whatsnew/3.3.html" />
|
||
|
||
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
||
<script type="text/javascript" src="../_static/switchers.js"></script>
|
||
|
||
|
||
|
||
<style>
|
||
@media only screen {
|
||
table.full-width-table {
|
||
width: 100%;
|
||
}
|
||
}
|
||
</style>
|
||
|
||
|
||
</head><body>
|
||
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
accesskey="I">index</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="right" >
|
||
<a href="3.2.html" title="What’s New In Python 3.2"
|
||
accesskey="N">next</a> |</li>
|
||
<li class="right" >
|
||
<a href="3.4.html" title="What’s New In Python 3.4"
|
||
accesskey="P">previous</a> |</li>
|
||
<li><img src="../_static/py.png" alt=""
|
||
style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li>
|
||
<span class="language_switcher_placeholder">en</span>
|
||
<span class="version_switcher_placeholder">3.7.4</span>
|
||
<a href="../index.html">Documentation </a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> »</li>
|
||
<li class="right">
|
||
|
||
|
||
<div class="inline-search" style="display: none" role="search">
|
||
<form class="inline-search" action="../search.html" method="get">
|
||
<input placeholder="Quick search" type="text" name="q" />
|
||
<input type="submit" value="Go" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
<script type="text/javascript">$('.inline-search').show(0);</script>
|
||
|
|
||
</li>
|
||
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<div class="section" id="what-s-new-in-python-3-3">
|
||
<h1>What’s New In Python 3.3<a class="headerlink" href="#what-s-new-in-python-3-3" title="Permalink to this headline">¶</a></h1>
|
||
<p>This article explains the new features in Python 3.3, compared to 3.2.
|
||
Python 3.3 was released on September 29, 2012. For full details,
|
||
see the <a class="reference external" href="https://docs.python.org/3.3/whatsnew/changelog.html">changelog</a>.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p><span class="target" id="index-0"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0398"><strong>PEP 398</strong></a> - Python 3.3 Release Schedule</p>
|
||
</div>
|
||
<div class="section" id="summary-release-highlights">
|
||
<h2>Summary – Release highlights<a class="headerlink" href="#summary-release-highlights" title="Permalink to this headline">¶</a></h2>
|
||
<p>New syntax features:</p>
|
||
<ul class="simple">
|
||
<li><p>New <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> expression for <a class="reference internal" href="#pep-380"><span class="std std-ref">generator delegation</span></a>.</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">u'unicode'</span></code> syntax is accepted again for <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> objects.</p></li>
|
||
</ul>
|
||
<p>New library modules:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/faulthandler.html#module-faulthandler" title="faulthandler: Dump the Python traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code></a> (helps debugging low-level crashes)</p></li>
|
||
<li><p><a class="reference internal" href="../library/ipaddress.html#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ipaddress</span></code></a> (high-level objects representing IP addresses and masks)</p></li>
|
||
<li><p><a class="reference internal" href="../library/lzma.html#module-lzma" title="lzma: A Python wrapper for the liblzma compression library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">lzma</span></code></a> (compress data using the XZ / LZMA algorithm)</p></li>
|
||
<li><p><a class="reference internal" href="../library/unittest.mock.html#module-unittest.mock" title="unittest.mock: Mock object library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest.mock</span></code></a> (replace parts of your system under test with mock objects)</p></li>
|
||
<li><p><a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a> (Python <a class="reference internal" href="#pep-405"><span class="std std-ref">virtual environments</span></a>, as in the
|
||
popular <code class="docutils literal notranslate"><span class="pre">virtualenv</span></code> package)</p></li>
|
||
</ul>
|
||
<p>New built-in features:</p>
|
||
<ul class="simple">
|
||
<li><p>Reworked <a class="reference internal" href="#pep-3151"><span class="std std-ref">I/O exception hierarchy</span></a>.</p></li>
|
||
</ul>
|
||
<p>Implementation improvements:</p>
|
||
<ul class="simple">
|
||
<li><p>Rewritten <a class="reference internal" href="#importlib"><span class="std std-ref">import machinery</span></a> based on <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a>.</p></li>
|
||
<li><p>More compact <a class="reference internal" href="#pep-393"><span class="std std-ref">unicode strings</span></a>.</p></li>
|
||
<li><p>More compact <a class="reference internal" href="#pep-412"><span class="std std-ref">attribute dictionaries</span></a>.</p></li>
|
||
</ul>
|
||
<p>Significantly Improved Library Modules:</p>
|
||
<ul class="simple">
|
||
<li><p>C Accelerator for the <a class="reference internal" href="#new-decimal"><span class="std std-ref">decimal</span></a> module.</p></li>
|
||
<li><p>Better unicode handling in the <a class="reference internal" href="#new-email"><span class="std std-ref">email</span></a> module
|
||
(<a class="reference internal" href="../glossary.html#term-provisional-package"><span class="xref std std-term">provisional</span></a>).</p></li>
|
||
</ul>
|
||
<p>Security improvements:</p>
|
||
<ul class="simple">
|
||
<li><p>Hash randomization is switched on by default.</p></li>
|
||
</ul>
|
||
<p>Please read on for a comprehensive list of user-facing changes.</p>
|
||
</div>
|
||
<div class="section" id="pep-405-virtual-environments">
|
||
<span id="pep-405"></span><h2>PEP 405: Virtual Environments<a class="headerlink" href="#pep-405-virtual-environments" title="Permalink to this headline">¶</a></h2>
|
||
<p>Virtual environments help create separate Python setups while sharing a
|
||
system-wide base install, for ease of maintenance. Virtual environments
|
||
have their own set of private site packages (i.e. locally-installed
|
||
libraries), and are optionally segregated from the system-wide site
|
||
packages. Their concept and implementation are inspired by the popular
|
||
<code class="docutils literal notranslate"><span class="pre">virtualenv</span></code> third-party package, but benefit from tighter integration
|
||
with the interpreter core.</p>
|
||
<p>This PEP adds the <a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a> module for programmatic access, and the
|
||
<code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> script for command-line access and
|
||
administration. The Python interpreter checks for a <code class="docutils literal notranslate"><span class="pre">pyvenv.cfg</span></code>,
|
||
file whose existence signals the base of a virtual environment’s directory
|
||
tree.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-1"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0405"><strong>PEP 405</strong></a> - Python Virtual Environments</dt><dd><p>PEP written by Carl Meyer; implementation by Carl Meyer and Vinay Sajip</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pep-420-implicit-namespace-packages">
|
||
<h2>PEP 420: Implicit Namespace Packages<a class="headerlink" href="#pep-420-implicit-namespace-packages" title="Permalink to this headline">¶</a></h2>
|
||
<p>Native support for package directories that don’t require <code class="docutils literal notranslate"><span class="pre">__init__.py</span></code>
|
||
marker files and can automatically span multiple path segments (inspired by
|
||
various third party approaches to namespace packages, as described in
|
||
<span class="target" id="index-2"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0420"><strong>PEP 420</strong></a>)</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-3"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0420"><strong>PEP 420</strong></a> - Implicit Namespace Packages</dt><dd><p>PEP written by Eric V. Smith; implementation by Eric V. Smith
|
||
and Barry Warsaw</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pep-3118-new-memoryview-implementation-and-buffer-protocol-documentation">
|
||
<span id="pep-3118-update"></span><h2>PEP 3118: New memoryview implementation and buffer protocol documentation<a class="headerlink" href="#pep-3118-new-memoryview-implementation-and-buffer-protocol-documentation" title="Permalink to this headline">¶</a></h2>
|
||
<p>The implementation of <span class="target" id="index-4"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3118"><strong>PEP 3118</strong></a> has been significantly improved.</p>
|
||
<p>The new memoryview implementation comprehensively fixes all ownership and
|
||
lifetime issues of dynamically allocated fields in the Py_buffer struct
|
||
that led to multiple crash reports. Additionally, several functions that
|
||
crashed or returned incorrect results for non-contiguous or multi-dimensional
|
||
input have been fixed.</p>
|
||
<p>The memoryview object now has a PEP-3118 compliant getbufferproc()
|
||
that checks the consumer’s request type. Many new features have been
|
||
added, most of them work in full generality for non-contiguous arrays
|
||
and arrays with suboffsets.</p>
|
||
<p>The documentation has been updated, clearly spelling out responsibilities
|
||
for both exporters and consumers. Buffer request flags are grouped into
|
||
basic and compound flags. The memory layout of non-contiguous and
|
||
multi-dimensional NumPy-style arrays is explained.</p>
|
||
<div class="section" id="features">
|
||
<h3>Features<a class="headerlink" href="#features" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>All native single character format specifiers in struct module syntax
|
||
(optionally prefixed with ‘@’) are now supported.</p></li>
|
||
<li><p>With some restrictions, the cast() method allows changing of format and
|
||
shape of C-contiguous arrays.</p></li>
|
||
<li><p>Multi-dimensional list representations are supported for any array type.</p></li>
|
||
<li><p>Multi-dimensional comparisons are supported for any array type.</p></li>
|
||
<li><p>One-dimensional memoryviews of hashable (read-only) types with formats B,
|
||
b or c are now hashable. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue13411">bpo-13411</a>.)</p></li>
|
||
<li><p>Arbitrary slicing of any 1-D arrays type is supported. For example, it
|
||
is now possible to reverse a memoryview in O(1) by using a negative step.</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="api-changes">
|
||
<h3>API changes<a class="headerlink" href="#api-changes" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>The maximum number of dimensions is officially limited to 64.</p></li>
|
||
<li><p>The representation of empty shape, strides and suboffsets is now
|
||
an empty tuple instead of <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p></li>
|
||
<li><p>Accessing a memoryview element with format ‘B’ (unsigned bytes)
|
||
now returns an integer (in accordance with the struct module syntax).
|
||
For returning a bytes object the view must be cast to ‘c’ first.</p></li>
|
||
<li><p>memoryview comparisons now use the logical structure of the operands
|
||
and compare all array elements by value. All format strings in struct
|
||
module syntax are supported. Views with unrecognised format strings
|
||
are still permitted, but will always compare as unequal, regardless
|
||
of view contents.</p></li>
|
||
<li><p>For further changes see <a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a> and <a class="reference internal" href="#porting-c-code">Porting C code</a>.</p></li>
|
||
</ul>
|
||
<p>(Contributed by Stefan Krah in <a class="reference external" href="https://bugs.python.org/issue10181">bpo-10181</a>.)</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p><span class="target" id="index-5"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3118"><strong>PEP 3118</strong></a> - Revising the Buffer Protocol</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pep-393-flexible-string-representation">
|
||
<span id="pep-393"></span><h2>PEP 393: Flexible String Representation<a class="headerlink" href="#pep-393-flexible-string-representation" title="Permalink to this headline">¶</a></h2>
|
||
<p>The Unicode string type is changed to support multiple internal
|
||
representations, depending on the character with the largest Unicode ordinal
|
||
(1, 2, or 4 bytes) in the represented string. This allows a space-efficient
|
||
representation in common cases, but gives access to full UCS-4 on all
|
||
systems. For compatibility with existing APIs, several representations may
|
||
exist in parallel; over time, this compatibility should be phased out.</p>
|
||
<p>On the Python side, there should be no downside to this change.</p>
|
||
<p>On the C API side, PEP 393 is fully backward compatible. The legacy API
|
||
should remain available at least five years. Applications using the legacy
|
||
API will not fully benefit of the memory reduction, or - worse - may use
|
||
a bit more memory, because Python may have to maintain two versions of each
|
||
string (in the legacy format and in the new efficient storage).</p>
|
||
<div class="section" id="functionality">
|
||
<h3>Functionality<a class="headerlink" href="#functionality" title="Permalink to this headline">¶</a></h3>
|
||
<p>Changes introduced by <span class="target" id="index-6"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0393"><strong>PEP 393</strong></a> are the following:</p>
|
||
<ul class="simple">
|
||
<li><p>Python now always supports the full range of Unicode code points, including
|
||
non-BMP ones (i.e. from <code class="docutils literal notranslate"><span class="pre">U+0000</span></code> to <code class="docutils literal notranslate"><span class="pre">U+10FFFF</span></code>). The distinction between
|
||
narrow and wide builds no longer exists and Python now behaves like a wide
|
||
build, even under Windows.</p></li>
|
||
<li><p>With the death of narrow builds, the problems specific to narrow builds have
|
||
also been fixed, for example:</p>
|
||
<ul>
|
||
<li><p><a class="reference internal" href="../library/functions.html#len" title="len"><code class="xref py py-func docutils literal notranslate"><span class="pre">len()</span></code></a> now always returns 1 for non-BMP characters,
|
||
so <code class="docutils literal notranslate"><span class="pre">len('\U0010FFFF')</span> <span class="pre">==</span> <span class="pre">1</span></code>;</p></li>
|
||
<li><p>surrogate pairs are not recombined in string literals,
|
||
so <code class="docutils literal notranslate"><span class="pre">'\uDBFF\uDFFF'</span> <span class="pre">!=</span> <span class="pre">'\U0010FFFF'</span></code>;</p></li>
|
||
<li><p>indexing or slicing non-BMP characters returns the expected value,
|
||
so <code class="docutils literal notranslate"><span class="pre">'\U0010FFFF'[0]</span></code> now returns <code class="docutils literal notranslate"><span class="pre">'\U0010FFFF'</span></code> and not <code class="docutils literal notranslate"><span class="pre">'\uDBFF'</span></code>;</p></li>
|
||
<li><p>all other functions in the standard library now correctly handle
|
||
non-BMP code points.</p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p>The value of <a class="reference internal" href="../library/sys.html#sys.maxunicode" title="sys.maxunicode"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.maxunicode</span></code></a> is now always <code class="docutils literal notranslate"><span class="pre">1114111</span></code> (<code class="docutils literal notranslate"><span class="pre">0x10FFFF</span></code>
|
||
in hexadecimal). The <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetMax()</span></code> function still returns
|
||
either <code class="docutils literal notranslate"><span class="pre">0xFFFF</span></code> or <code class="docutils literal notranslate"><span class="pre">0x10FFFF</span></code> for backward compatibility, and it should
|
||
not be used with the new Unicode API (see <a class="reference external" href="https://bugs.python.org/issue13054">bpo-13054</a>).</p></li>
|
||
<li><p>The <code class="file docutils literal notranslate"><span class="pre">./configure</span></code> flag <code class="docutils literal notranslate"><span class="pre">--with-wide-unicode</span></code> has been removed.</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="performance-and-resource-usage">
|
||
<h3>Performance and resource usage<a class="headerlink" href="#performance-and-resource-usage" title="Permalink to this headline">¶</a></h3>
|
||
<p>The storage of Unicode strings now depends on the highest code point in the string:</p>
|
||
<ul class="simple">
|
||
<li><p>pure ASCII and Latin1 strings (<code class="docutils literal notranslate"><span class="pre">U+0000-U+00FF</span></code>) use 1 byte per code point;</p></li>
|
||
<li><p>BMP strings (<code class="docutils literal notranslate"><span class="pre">U+0000-U+FFFF</span></code>) use 2 bytes per code point;</p></li>
|
||
<li><p>non-BMP strings (<code class="docutils literal notranslate"><span class="pre">U+10000-U+10FFFF</span></code>) use 4 bytes per code point.</p></li>
|
||
</ul>
|
||
<p>The net effect is that for most applications, memory usage of string
|
||
storage should decrease significantly - especially compared to former
|
||
wide unicode builds - as, in many cases, strings will be pure ASCII
|
||
even in international contexts (because many strings store non-human
|
||
language data, such as XML fragments, HTTP headers, JSON-encoded data,
|
||
etc.). We also hope that it will, for the same reasons, increase CPU
|
||
cache efficiency on non-trivial applications. The memory usage of
|
||
Python 3.3 is two to three times smaller than Python 3.2, and a little
|
||
bit better than Python 2.7, on a Django benchmark (see the PEP for
|
||
details).</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-7"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0393"><strong>PEP 393</strong></a> - Flexible String Representation</dt><dd><p>PEP written by Martin von Löwis; implementation by Torsten Becker
|
||
and Martin von Löwis.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pep-397-python-launcher-for-windows">
|
||
<span id="pep-397"></span><h2>PEP 397: Python Launcher for Windows<a class="headerlink" href="#pep-397-python-launcher-for-windows" title="Permalink to this headline">¶</a></h2>
|
||
<p>The Python 3.3 Windows installer now includes a <code class="docutils literal notranslate"><span class="pre">py</span></code> launcher application
|
||
that can be used to launch Python applications in a version independent
|
||
fashion.</p>
|
||
<p>This launcher is invoked implicitly when double-clicking <code class="docutils literal notranslate"><span class="pre">*.py</span></code> files.
|
||
If only a single Python version is installed on the system, that version
|
||
will be used to run the file. If multiple versions are installed, the most
|
||
recent version is used by default, but this can be overridden by including
|
||
a Unix-style “shebang line” in the Python script.</p>
|
||
<p>The launcher can also be used explicitly from the command line as the <code class="docutils literal notranslate"><span class="pre">py</span></code>
|
||
application. Running <code class="docutils literal notranslate"><span class="pre">py</span></code> follows the same version selection rules as
|
||
implicitly launching scripts, but a more specific version can be selected
|
||
by passing appropriate arguments (such as <code class="docutils literal notranslate"><span class="pre">-3</span></code> to request Python 3 when
|
||
Python 2 is also installed, or <code class="docutils literal notranslate"><span class="pre">-2.6</span></code> to specifically request an earlier
|
||
Python version when a more recent version is installed).</p>
|
||
<p>In addition to the launcher, the Windows installer now includes an
|
||
option to add the newly installed Python to the system PATH. (Contributed
|
||
by Brian Curtin in <a class="reference external" href="https://bugs.python.org/issue3561">bpo-3561</a>.)</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-8"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0397"><strong>PEP 397</strong></a> - Python Launcher for Windows</dt><dd><p>PEP written by Mark Hammond and Martin v. Löwis; implementation by
|
||
Vinay Sajip.</p>
|
||
</dd>
|
||
</dl>
|
||
<p>Launcher documentation: <a class="reference internal" href="../using/windows.html#launcher"><span class="std std-ref">Python Launcher for Windows</span></a></p>
|
||
<p>Installer PATH modification: <a class="reference internal" href="../using/windows.html#windows-path-mod"><span class="std std-ref">Finding the Python executable</span></a></p>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pep-3151-reworking-the-os-and-io-exception-hierarchy">
|
||
<span id="pep-3151"></span><h2>PEP 3151: Reworking the OS and IO exception hierarchy<a class="headerlink" href="#pep-3151-reworking-the-os-and-io-exception-hierarchy" title="Permalink to this headline">¶</a></h2>
|
||
<p>The hierarchy of exceptions raised by operating system errors is now both
|
||
simplified and finer-grained.</p>
|
||
<p>You don’t have to worry anymore about choosing the appropriate exception
|
||
type between <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>, <a class="reference internal" href="../library/exceptions.html#IOError" title="IOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IOError</span></code></a>, <a class="reference internal" href="../library/exceptions.html#EnvironmentError" title="EnvironmentError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">EnvironmentError</span></code></a>,
|
||
<a class="reference internal" href="../library/exceptions.html#WindowsError" title="WindowsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">WindowsError</span></code></a>, <code class="xref py py-exc docutils literal notranslate"><span class="pre">mmap.error</span></code>, <a class="reference internal" href="../library/socket.html#socket.error" title="socket.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">socket.error</span></code></a> or
|
||
<a class="reference internal" href="../library/select.html#select.error" title="select.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">select.error</span></code></a>. All these exception types are now only one:
|
||
<a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>. The other names are kept as aliases for compatibility
|
||
reasons.</p>
|
||
<p>Also, it is now easier to catch a specific error condition. Instead of
|
||
inspecting the <code class="docutils literal notranslate"><span class="pre">errno</span></code> attribute (or <code class="docutils literal notranslate"><span class="pre">args[0]</span></code>) for a particular
|
||
constant from the <a class="reference internal" href="../library/errno.html#module-errno" title="errno: Standard errno system symbols."><code class="xref py py-mod docutils literal notranslate"><span class="pre">errno</span></code></a> module, you can catch the adequate
|
||
<a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> subclass. The available subclasses are the following:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#BlockingIOError" title="BlockingIOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BlockingIOError</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#ChildProcessError" title="ChildProcessError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ChildProcessError</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#ConnectionError" title="ConnectionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionError</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#FileExistsError" title="FileExistsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileExistsError</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#IsADirectoryError" title="IsADirectoryError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IsADirectoryError</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#NotADirectoryError" title="NotADirectoryError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotADirectoryError</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#PermissionError" title="PermissionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PermissionError</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#ProcessLookupError" title="ProcessLookupError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ProcessLookupError</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#TimeoutError" title="TimeoutError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TimeoutError</span></code></a></p></li>
|
||
</ul>
|
||
<p>And the <a class="reference internal" href="../library/exceptions.html#ConnectionError" title="ConnectionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionError</span></code></a> itself has finer-grained subclasses:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#BrokenPipeError" title="BrokenPipeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BrokenPipeError</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#ConnectionAbortedError" title="ConnectionAbortedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionAbortedError</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#ConnectionRefusedError" title="ConnectionRefusedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionRefusedError</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#ConnectionResetError" title="ConnectionResetError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionResetError</span></code></a></p></li>
|
||
</ul>
|
||
<p>Thanks to the new exceptions, common usages of the <a class="reference internal" href="../library/errno.html#module-errno" title="errno: Standard errno system symbols."><code class="xref py py-mod docutils literal notranslate"><span class="pre">errno</span></code></a> can now be
|
||
avoided. For example, the following code written for Python 3.2:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">errno</span> <span class="k">import</span> <span class="n">ENOENT</span><span class="p">,</span> <span class="n">EACCES</span><span class="p">,</span> <span class="n">EPERM</span>
|
||
|
||
<span class="k">try</span><span class="p">:</span>
|
||
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">"document.txt"</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
|
||
<span class="n">content</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
|
||
<span class="k">except</span> <span class="ne">IOError</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span>
|
||
<span class="k">if</span> <span class="n">err</span><span class="o">.</span><span class="n">errno</span> <span class="o">==</span> <span class="n">ENOENT</span><span class="p">:</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="s2">"document.txt file is missing"</span><span class="p">)</span>
|
||
<span class="k">elif</span> <span class="n">err</span><span class="o">.</span><span class="n">errno</span> <span class="ow">in</span> <span class="p">(</span><span class="n">EACCES</span><span class="p">,</span> <span class="n">EPERM</span><span class="p">):</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="s2">"You are not allowed to read document.txt"</span><span class="p">)</span>
|
||
<span class="k">else</span><span class="p">:</span>
|
||
<span class="k">raise</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>can now be written without the <a class="reference internal" href="../library/errno.html#module-errno" title="errno: Standard errno system symbols."><code class="xref py py-mod docutils literal notranslate"><span class="pre">errno</span></code></a> import and without manual
|
||
inspection of exception attributes:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="p">:</span>
|
||
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">"document.txt"</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
|
||
<span class="n">content</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
|
||
<span class="k">except</span> <span class="ne">FileNotFoundError</span><span class="p">:</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="s2">"document.txt file is missing"</span><span class="p">)</span>
|
||
<span class="k">except</span> <span class="ne">PermissionError</span><span class="p">:</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="s2">"You are not allowed to read document.txt"</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-9"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3151"><strong>PEP 3151</strong></a> - Reworking the OS and IO Exception Hierarchy</dt><dd><p>PEP written and implemented by Antoine Pitrou</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pep-380-syntax-for-delegating-to-a-subgenerator">
|
||
<span id="pep-380"></span><span id="index-10"></span><h2>PEP 380: Syntax for Delegating to a Subgenerator<a class="headerlink" href="#pep-380-syntax-for-delegating-to-a-subgenerator" title="Permalink to this headline">¶</a></h2>
|
||
<p>PEP 380 adds the <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> expression, allowing a <a class="reference internal" href="../glossary.html#term-generator"><span class="xref std std-term">generator</span></a> to
|
||
delegate
|
||
part of its operations to another generator. This allows a section of code
|
||
containing <a class="reference internal" href="../reference/simple_stmts.html#yield"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">yield</span></code></a> to be factored out and placed in another generator.
|
||
Additionally, the subgenerator is allowed to return with a value, and the
|
||
value is made available to the delegating generator.</p>
|
||
<p>While designed primarily for use in delegating to a subgenerator, the <code class="docutils literal notranslate"><span class="pre">yield</span>
|
||
<span class="pre">from</span></code> expression actually allows delegation to arbitrary subiterators.</p>
|
||
<p>For simple iterators, <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span> <span class="pre">iterable</span></code> is essentially just a shortened
|
||
form of <code class="docutils literal notranslate"><span class="pre">for</span> <span class="pre">item</span> <span class="pre">in</span> <span class="pre">iterable:</span> <span class="pre">yield</span> <span class="pre">item</span></code>:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">def</span> <span class="nf">g</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="k">yield from</span> <span class="nb">range</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
|
||
<span class="gp">... </span> <span class="k">yield from</span> <span class="nb">range</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
|
||
<span class="gp">...</span>
|
||
<span class="gp">>>> </span><span class="nb">list</span><span class="p">(</span><span class="n">g</span><span class="p">(</span><span class="mi">5</span><span class="p">))</span>
|
||
<span class="go">[5, 4, 3, 2, 1, 0, 1, 2, 3, 4]</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>However, unlike an ordinary loop, <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> allows subgenerators to
|
||
receive sent and thrown values directly from the calling scope, and
|
||
return a final value to the outer generator:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">def</span> <span class="nf">accumulate</span><span class="p">():</span>
|
||
<span class="gp">... </span> <span class="n">tally</span> <span class="o">=</span> <span class="mi">0</span>
|
||
<span class="gp">... </span> <span class="k">while</span> <span class="mi">1</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="nb">next</span> <span class="o">=</span> <span class="k">yield</span>
|
||
<span class="gp">... </span> <span class="k">if</span> <span class="nb">next</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="k">return</span> <span class="n">tally</span>
|
||
<span class="gp">... </span> <span class="n">tally</span> <span class="o">+=</span> <span class="nb">next</span>
|
||
<span class="gp">...</span>
|
||
<span class="gp">>>> </span><span class="k">def</span> <span class="nf">gather_tallies</span><span class="p">(</span><span class="n">tallies</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="k">while</span> <span class="mi">1</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="n">tally</span> <span class="o">=</span> <span class="k">yield from</span> <span class="n">accumulate</span><span class="p">()</span>
|
||
<span class="gp">... </span> <span class="n">tallies</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tally</span><span class="p">)</span>
|
||
<span class="gp">...</span>
|
||
<span class="gp">>>> </span><span class="n">tallies</span> <span class="o">=</span> <span class="p">[]</span>
|
||
<span class="gp">>>> </span><span class="n">acc</span> <span class="o">=</span> <span class="n">gather_tallies</span><span class="p">(</span><span class="n">tallies</span><span class="p">)</span>
|
||
<span class="gp">>>> </span><span class="nb">next</span><span class="p">(</span><span class="n">acc</span><span class="p">)</span> <span class="c1"># Ensure the accumulator is ready to accept values</span>
|
||
<span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="n">acc</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
|
||
<span class="gp">...</span>
|
||
<span class="gp">>>> </span><span class="n">acc</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span> <span class="c1"># Finish the first tally</span>
|
||
<span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="n">acc</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
|
||
<span class="gp">...</span>
|
||
<span class="gp">>>> </span><span class="n">acc</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span> <span class="c1"># Finish the second tally</span>
|
||
<span class="gp">>>> </span><span class="n">tallies</span>
|
||
<span class="go">[6, 10]</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>The main principle driving this change is to allow even generators that are
|
||
designed to be used with the <code class="docutils literal notranslate"><span class="pre">send</span></code> and <code class="docutils literal notranslate"><span class="pre">throw</span></code> methods to be split into
|
||
multiple subgenerators as easily as a single large function can be split into
|
||
multiple subfunctions.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-11"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0380"><strong>PEP 380</strong></a> - Syntax for Delegating to a Subgenerator</dt><dd><p>PEP written by Greg Ewing; implementation by Greg Ewing, integrated into
|
||
3.3 by Renaud Blanch, Ryan Kelly and Nick Coghlan; documentation by
|
||
Zbigniew Jędrzejewski-Szmek and Nick Coghlan</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pep-409-suppressing-exception-context">
|
||
<h2>PEP 409: Suppressing exception context<a class="headerlink" href="#pep-409-suppressing-exception-context" title="Permalink to this headline">¶</a></h2>
|
||
<p>PEP 409 introduces new syntax that allows the display of the chained
|
||
exception context to be disabled. This allows cleaner error messages in
|
||
applications that convert between exception types:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">class</span> <span class="nc">D</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">extra</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="bp">self</span><span class="o">.</span><span class="n">_extra_attributes</span> <span class="o">=</span> <span class="n">extra</span>
|
||
<span class="gp">... </span> <span class="k">def</span> <span class="nf">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attr</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="k">try</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_extra_attributes</span><span class="p">[</span><span class="n">attr</span><span class="p">]</span>
|
||
<span class="gp">... </span> <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="n">attr</span><span class="p">)</span> <span class="kn">from</span> <span class="nn">None</span>
|
||
<span class="gp">...</span>
|
||
<span class="gp">>>> </span><span class="n">D</span><span class="p">({})</span><span class="o">.</span><span class="n">x</span>
|
||
<span class="gt">Traceback (most recent call last):</span>
|
||
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span>
|
||
File <span class="nb">"<stdin>"</span>, line <span class="m">8</span>, in <span class="n">__getattr__</span>
|
||
<span class="gr">AttributeError</span>: <span class="n">x</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Without the <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">None</span></code> suffix to suppress the cause, the original
|
||
exception would be displayed by default:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">class</span> <span class="nc">C</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">extra</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="bp">self</span><span class="o">.</span><span class="n">_extra_attributes</span> <span class="o">=</span> <span class="n">extra</span>
|
||
<span class="gp">... </span> <span class="k">def</span> <span class="nf">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attr</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="k">try</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_extra_attributes</span><span class="p">[</span><span class="n">attr</span><span class="p">]</span>
|
||
<span class="gp">... </span> <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="n">attr</span><span class="p">)</span>
|
||
<span class="gp">...</span>
|
||
<span class="gp">>>> </span><span class="n">C</span><span class="p">({})</span><span class="o">.</span><span class="n">x</span>
|
||
<span class="gt">Traceback (most recent call last):</span>
|
||
File <span class="nb">"<stdin>"</span>, line <span class="m">6</span>, in <span class="n">__getattr__</span>
|
||
<span class="gr">KeyError</span>: <span class="n">'x'</span>
|
||
|
||
<span class="go">During handling of the above exception, another exception occurred:</span>
|
||
|
||
<span class="gt">Traceback (most recent call last):</span>
|
||
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span>
|
||
File <span class="nb">"<stdin>"</span>, line <span class="m">8</span>, in <span class="n">__getattr__</span>
|
||
<span class="gr">AttributeError</span>: <span class="n">x</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>No debugging capability is lost, as the original exception context remains
|
||
available if needed (for example, if an intervening library has incorrectly
|
||
suppressed valuable underlying details):</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">try</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="n">D</span><span class="p">({})</span><span class="o">.</span><span class="n">x</span>
|
||
<span class="gp">... </span><span class="k">except</span> <span class="ne">AttributeError</span> <span class="k">as</span> <span class="n">exc</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="n">exc</span><span class="o">.</span><span class="n">__context__</span><span class="p">))</span>
|
||
<span class="gp">...</span>
|
||
<span class="go">KeyError('x',)</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-12"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0409"><strong>PEP 409</strong></a> - Suppressing exception context</dt><dd><p>PEP written by Ethan Furman; implemented by Ethan Furman and Nick
|
||
Coghlan.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pep-414-explicit-unicode-literals">
|
||
<h2>PEP 414: Explicit Unicode literals<a class="headerlink" href="#pep-414-explicit-unicode-literals" title="Permalink to this headline">¶</a></h2>
|
||
<p>To ease the transition from Python 2 for Unicode aware Python applications
|
||
that make heavy use of Unicode literals, Python 3.3 once again supports the
|
||
“<code class="docutils literal notranslate"><span class="pre">u</span></code>” prefix for string literals. This prefix has no semantic significance
|
||
in Python 3, it is provided solely to reduce the number of purely mechanical
|
||
changes in migrating to Python 3, making it easier for developers to focus on
|
||
the more significant semantic changes (such as the stricter default
|
||
separation of binary and text data).</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-13"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0414"><strong>PEP 414</strong></a> - Explicit Unicode literals</dt><dd><p>PEP written by Armin Ronacher.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pep-3155-qualified-name-for-classes-and-functions">
|
||
<h2>PEP 3155: Qualified name for classes and functions<a class="headerlink" href="#pep-3155-qualified-name-for-classes-and-functions" title="Permalink to this headline">¶</a></h2>
|
||
<p>Functions and class objects have a new <code class="docutils literal notranslate"><span class="pre">__qualname__</span></code> attribute representing
|
||
the “path” from the module top-level to their definition. For global functions
|
||
and classes, this is the same as <code class="docutils literal notranslate"><span class="pre">__name__</span></code>. For other functions and classes,
|
||
it provides better information about where they were actually defined, and
|
||
how they might be accessible from the global scope.</p>
|
||
<p>Example with (non-bound) methods:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">class</span> <span class="nc">C</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="k">def</span> <span class="nf">meth</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="k">pass</span>
|
||
<span class="gp">>>> </span><span class="n">C</span><span class="o">.</span><span class="n">meth</span><span class="o">.</span><span class="vm">__name__</span>
|
||
<span class="go">'meth'</span>
|
||
<span class="gp">>>> </span><span class="n">C</span><span class="o">.</span><span class="n">meth</span><span class="o">.</span><span class="vm">__qualname__</span>
|
||
<span class="go">'C.meth'</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Example with nested classes:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">class</span> <span class="nc">C</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="k">class</span> <span class="nc">D</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="k">def</span> <span class="nf">meth</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="k">pass</span>
|
||
<span class="gp">...</span>
|
||
<span class="gp">>>> </span><span class="n">C</span><span class="o">.</span><span class="n">D</span><span class="o">.</span><span class="vm">__name__</span>
|
||
<span class="go">'D'</span>
|
||
<span class="gp">>>> </span><span class="n">C</span><span class="o">.</span><span class="n">D</span><span class="o">.</span><span class="vm">__qualname__</span>
|
||
<span class="go">'C.D'</span>
|
||
<span class="gp">>>> </span><span class="n">C</span><span class="o">.</span><span class="n">D</span><span class="o">.</span><span class="n">meth</span><span class="o">.</span><span class="vm">__name__</span>
|
||
<span class="go">'meth'</span>
|
||
<span class="gp">>>> </span><span class="n">C</span><span class="o">.</span><span class="n">D</span><span class="o">.</span><span class="n">meth</span><span class="o">.</span><span class="vm">__qualname__</span>
|
||
<span class="go">'C.D.meth'</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Example with nested functions:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">def</span> <span class="nf">outer</span><span class="p">():</span>
|
||
<span class="gp">... </span> <span class="k">def</span> <span class="nf">inner</span><span class="p">():</span>
|
||
<span class="gp">... </span> <span class="k">pass</span>
|
||
<span class="gp">... </span> <span class="k">return</span> <span class="n">inner</span>
|
||
<span class="gp">...</span>
|
||
<span class="gp">>>> </span><span class="n">outer</span><span class="p">()</span><span class="o">.</span><span class="vm">__name__</span>
|
||
<span class="go">'inner'</span>
|
||
<span class="gp">>>> </span><span class="n">outer</span><span class="p">()</span><span class="o">.</span><span class="vm">__qualname__</span>
|
||
<span class="go">'outer.<locals>.inner'</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>The string representation of those objects is also changed to include the
|
||
new, more precise information:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">str</span><span class="p">(</span><span class="n">C</span><span class="o">.</span><span class="n">D</span><span class="p">)</span>
|
||
<span class="go">"<class '__main__.C.D'>"</span>
|
||
<span class="gp">>>> </span><span class="nb">str</span><span class="p">(</span><span class="n">C</span><span class="o">.</span><span class="n">D</span><span class="o">.</span><span class="n">meth</span><span class="p">)</span>
|
||
<span class="go">'<function C.D.meth at 0x7f46b9fe31e0>'</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-14"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3155"><strong>PEP 3155</strong></a> - Qualified name for classes and functions</dt><dd><p>PEP written and implemented by Antoine Pitrou.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pep-412-key-sharing-dictionary">
|
||
<span id="pep-412"></span><h2>PEP 412: Key-Sharing Dictionary<a class="headerlink" href="#pep-412-key-sharing-dictionary" title="Permalink to this headline">¶</a></h2>
|
||
<p>Dictionaries used for the storage of objects’ attributes are now able to
|
||
share part of their internal storage between each other (namely, the part
|
||
which stores the keys and their respective hashes). This reduces the memory
|
||
consumption of programs creating many instances of non-builtin types.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-15"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0412"><strong>PEP 412</strong></a> - Key-Sharing Dictionary</dt><dd><p>PEP written and implemented by Mark Shannon.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pep-362-function-signature-object">
|
||
<h2>PEP 362: Function Signature Object<a class="headerlink" href="#pep-362-function-signature-object" title="Permalink to this headline">¶</a></h2>
|
||
<p>A new function <a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.signature()</span></code></a> makes introspection of python
|
||
callables easy and straightforward. A broad range of callables is supported:
|
||
python functions, decorated or not, classes, and <a class="reference internal" href="../library/functools.html#functools.partial" title="functools.partial"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.partial()</span></code></a>
|
||
objects. New classes <a class="reference internal" href="../library/inspect.html#inspect.Signature" title="inspect.Signature"><code class="xref py py-class docutils literal notranslate"><span class="pre">inspect.Signature</span></code></a>, <a class="reference internal" href="../library/inspect.html#inspect.Parameter" title="inspect.Parameter"><code class="xref py py-class docutils literal notranslate"><span class="pre">inspect.Parameter</span></code></a>
|
||
and <a class="reference internal" href="../library/inspect.html#inspect.BoundArguments" title="inspect.BoundArguments"><code class="xref py py-class docutils literal notranslate"><span class="pre">inspect.BoundArguments</span></code></a> hold information about the call signatures,
|
||
such as, annotations, default values, parameters kinds, and bound arguments,
|
||
which considerably simplifies writing decorators and any code that validates
|
||
or amends calling signatures or arguments.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-16"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0362"><strong>PEP 362</strong></a>: - Function Signature Object</dt><dd><p>PEP written by Brett Cannon, Yury Selivanov, Larry Hastings, Jiwon Seo;
|
||
implemented by Yury Selivanov.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pep-421-adding-sys-implementation">
|
||
<h2>PEP 421: Adding sys.implementation<a class="headerlink" href="#pep-421-adding-sys-implementation" title="Permalink to this headline">¶</a></h2>
|
||
<p>A new attribute on the <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> module exposes details specific to the
|
||
implementation of the currently running interpreter. The initial set of
|
||
attributes on <a class="reference internal" href="../library/sys.html#sys.implementation" title="sys.implementation"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.implementation</span></code></a> are <code class="docutils literal notranslate"><span class="pre">name</span></code>, <code class="docutils literal notranslate"><span class="pre">version</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">hexversion</span></code>, and <code class="docutils literal notranslate"><span class="pre">cache_tag</span></code>.</p>
|
||
<p>The intention of <code class="docutils literal notranslate"><span class="pre">sys.implementation</span></code> is to consolidate into one namespace
|
||
the implementation-specific data used by the standard library. This allows
|
||
different Python implementations to share a single standard library code base
|
||
much more easily. In its initial state, <code class="docutils literal notranslate"><span class="pre">sys.implementation</span></code> holds only a
|
||
small portion of the implementation-specific data. Over time that ratio will
|
||
shift in order to make the standard library more portable.</p>
|
||
<p>One example of improved standard library portability is <code class="docutils literal notranslate"><span class="pre">cache_tag</span></code>. As of
|
||
Python 3.3, <code class="docutils literal notranslate"><span class="pre">sys.implementation.cache_tag</span></code> is used by <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> to
|
||
support <span class="target" id="index-17"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3147"><strong>PEP 3147</strong></a> compliance. Any Python implementation that uses
|
||
<code class="docutils literal notranslate"><span class="pre">importlib</span></code> for its built-in import system may use <code class="docutils literal notranslate"><span class="pre">cache_tag</span></code> to control
|
||
the caching behavior for modules.</p>
|
||
<div class="section" id="simplenamespace">
|
||
<h3>SimpleNamespace<a class="headerlink" href="#simplenamespace" title="Permalink to this headline">¶</a></h3>
|
||
<p>The implementation of <code class="docutils literal notranslate"><span class="pre">sys.implementation</span></code> also introduces a new type to
|
||
Python: <a class="reference internal" href="../library/types.html#types.SimpleNamespace" title="types.SimpleNamespace"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.SimpleNamespace</span></code></a>. In contrast to a mapping-based
|
||
namespace, like <a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a>, <code class="docutils literal notranslate"><span class="pre">SimpleNamespace</span></code> is attribute-based, like
|
||
<a class="reference internal" href="../library/functions.html#object" title="object"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a>. However, unlike <code class="docutils literal notranslate"><span class="pre">object</span></code>, <code class="docutils literal notranslate"><span class="pre">SimpleNamespace</span></code> instances
|
||
are writable. This means that you can add, remove, and modify the namespace
|
||
through normal attribute access.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-18"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0421"><strong>PEP 421</strong></a> - Adding sys.implementation</dt><dd><p>PEP written and implemented by Eric Snow.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="using-importlib-as-the-implementation-of-import">
|
||
<span id="importlib"></span><h2>Using importlib as the Implementation of Import<a class="headerlink" href="#using-importlib-as-the-implementation-of-import" title="Permalink to this headline">¶</a></h2>
|
||
<p><a class="reference external" href="https://bugs.python.org/issue2377">bpo-2377</a> - Replace __import__ w/ importlib.__import__
|
||
<a class="reference external" href="https://bugs.python.org/issue13959">bpo-13959</a> - Re-implement parts of <a class="reference internal" href="../library/imp.html#module-imp" title="imp: Access the implementation of the import statement. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code></a> in pure Python
|
||
<a class="reference external" href="https://bugs.python.org/issue14605">bpo-14605</a> - Make import machinery explicit
|
||
<a class="reference external" href="https://bugs.python.org/issue14646">bpo-14646</a> - Require loaders set __loader__ and __package__</p>
|
||
<p>The <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> function is now powered by <a class="reference internal" href="../library/importlib.html#importlib.__import__" title="importlib.__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.__import__()</span></code></a>.
|
||
This work leads to the completion of “phase 2” of <span class="target" id="index-19"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0302"><strong>PEP 302</strong></a>. There are
|
||
multiple benefits to this change. First, it has allowed for more of the
|
||
machinery powering import to be exposed instead of being implicit and hidden
|
||
within the C code. It also provides a single implementation for all Python VMs
|
||
supporting Python 3.3 to use, helping to end any VM-specific deviations in
|
||
import semantics. And finally it eases the maintenance of import, allowing for
|
||
future growth to occur.</p>
|
||
<p>For the common user, there should be no visible change in semantics. For
|
||
those whose code currently manipulates import or calls import
|
||
programmatically, the code changes that might possibly be required are covered
|
||
in the <a class="reference internal" href="#porting-python-code">Porting Python code</a> section of this document.</p>
|
||
<div class="section" id="new-apis">
|
||
<h3>New APIs<a class="headerlink" href="#new-apis" title="Permalink to this headline">¶</a></h3>
|
||
<p>One of the large benefits of this work is the exposure of what goes into
|
||
making the import statement work. That means the various importers that were
|
||
once implicit are now fully exposed as part of the <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> package.</p>
|
||
<p>The abstract base classes defined in <a class="reference internal" href="../library/importlib.html#module-importlib.abc" title="importlib.abc: Abstract base classes related to import"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.abc</span></code></a> have been expanded
|
||
to properly delineate between <a class="reference internal" href="../glossary.html#term-meta-path-finder"><span class="xref std std-term">meta path finders</span></a>
|
||
and <a class="reference internal" href="../glossary.html#term-path-entry-finder"><span class="xref std std-term">path entry finders</span></a> by introducing
|
||
<a class="reference internal" href="../library/importlib.html#importlib.abc.MetaPathFinder" title="importlib.abc.MetaPathFinder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.MetaPathFinder</span></code></a> and
|
||
<a class="reference internal" href="../library/importlib.html#importlib.abc.PathEntryFinder" title="importlib.abc.PathEntryFinder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder</span></code></a>, respectively. The old ABC of
|
||
<a class="reference internal" href="../library/importlib.html#importlib.abc.Finder" title="importlib.abc.Finder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.Finder</span></code></a> is now only provided for backwards-compatibility
|
||
and does not enforce any method requirements.</p>
|
||
<p>In terms of finders, <a class="reference internal" href="../library/importlib.html#importlib.machinery.FileFinder" title="importlib.machinery.FileFinder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.FileFinder</span></code></a> exposes the
|
||
mechanism used to search for source and bytecode files of a module. Previously
|
||
this class was an implicit member of <a class="reference internal" href="../library/sys.html#sys.path_hooks" title="sys.path_hooks"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.path_hooks</span></code></a>.</p>
|
||
<p>For loaders, the new abstract base class <a class="reference internal" href="../library/importlib.html#importlib.abc.FileLoader" title="importlib.abc.FileLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.FileLoader</span></code></a> helps
|
||
write a loader that uses the file system as the storage mechanism for a module’s
|
||
code. The loader for source files
|
||
(<a class="reference internal" href="../library/importlib.html#importlib.machinery.SourceFileLoader" title="importlib.machinery.SourceFileLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.SourceFileLoader</span></code></a>), sourceless bytecode files
|
||
(<a class="reference internal" href="../library/importlib.html#importlib.machinery.SourcelessFileLoader" title="importlib.machinery.SourcelessFileLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.SourcelessFileLoader</span></code></a>), and extension modules
|
||
(<a class="reference internal" href="../library/importlib.html#importlib.machinery.ExtensionFileLoader" title="importlib.machinery.ExtensionFileLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.ExtensionFileLoader</span></code></a>) are now available for
|
||
direct use.</p>
|
||
<p><a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> now has <code class="docutils literal notranslate"><span class="pre">name</span></code> and <code class="docutils literal notranslate"><span class="pre">path</span></code> attributes which are set when
|
||
there is relevant data to provide. The message for failed imports will also
|
||
provide the full name of the module now instead of just the tail end of the
|
||
module’s name.</p>
|
||
<p>The <a class="reference internal" href="../library/importlib.html#importlib.invalidate_caches" title="importlib.invalidate_caches"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.invalidate_caches()</span></code></a> function will now call the method with
|
||
the same name on all finders cached in <a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.path_importer_cache</span></code></a> to help
|
||
clean up any stored state as necessary.</p>
|
||
</div>
|
||
<div class="section" id="visible-changes">
|
||
<h3>Visible Changes<a class="headerlink" href="#visible-changes" title="Permalink to this headline">¶</a></h3>
|
||
<p>For potential required changes to code, see the <a class="reference internal" href="#porting-python-code">Porting Python code</a>
|
||
section.</p>
|
||
<p>Beyond the expanse of what <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> now exposes, there are other
|
||
visible changes to import. The biggest is that <a class="reference internal" href="../library/sys.html#sys.meta_path" title="sys.meta_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.meta_path</span></code></a> and
|
||
<a class="reference internal" href="../library/sys.html#sys.path_hooks" title="sys.path_hooks"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.path_hooks</span></code></a> now store all of the meta path finders and path entry
|
||
hooks used by import. Previously the finders were implicit and hidden within
|
||
the C code of import instead of being directly exposed. This means that one can
|
||
now easily remove or change the order of the various finders to fit one’s needs.</p>
|
||
<p>Another change is that all modules have a <code class="docutils literal notranslate"><span class="pre">__loader__</span></code> attribute, storing the
|
||
loader used to create the module. <span class="target" id="index-20"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0302"><strong>PEP 302</strong></a> has been updated to make this
|
||
attribute mandatory for loaders to implement, so in the future once 3rd-party
|
||
loaders have been updated people will be able to rely on the existence of the
|
||
attribute. Until such time, though, import is setting the module post-load.</p>
|
||
<p>Loaders are also now expected to set the <code class="docutils literal notranslate"><span class="pre">__package__</span></code> attribute from
|
||
<span class="target" id="index-21"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0366"><strong>PEP 366</strong></a>. Once again, import itself is already setting this on all loaders
|
||
from <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> and import itself is setting the attribute post-load.</p>
|
||
<p><code class="docutils literal notranslate"><span class="pre">None</span></code> is now inserted into <a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.path_importer_cache</span></code></a> when no finder
|
||
can be found on <a class="reference internal" href="../library/sys.html#sys.path_hooks" title="sys.path_hooks"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.path_hooks</span></code></a>. Since <a class="reference internal" href="../library/imp.html#imp.NullImporter" title="imp.NullImporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">imp.NullImporter</span></code></a> is not
|
||
directly exposed on <a class="reference internal" href="../library/sys.html#sys.path_hooks" title="sys.path_hooks"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.path_hooks</span></code></a> it could no longer be relied upon to
|
||
always be available to use as a value representing no finder found.</p>
|
||
<p>All other changes relate to semantic changes which should be taken into
|
||
consideration when updating code for Python 3.3, and thus should be read about
|
||
in the <a class="reference internal" href="#porting-python-code">Porting Python code</a> section of this document.</p>
|
||
<p>(Implementation by Brett Cannon)</p>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="other-language-changes">
|
||
<h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Permalink to this headline">¶</a></h2>
|
||
<p>Some smaller changes made to the core Python language are:</p>
|
||
<ul>
|
||
<li><p>Added support for Unicode name aliases and named sequences.
|
||
Both <a class="reference internal" href="../library/unicodedata.html#unicodedata.lookup" title="unicodedata.lookup"><code class="xref py py-func docutils literal notranslate"><span class="pre">unicodedata.lookup()</span></code></a> and <code class="docutils literal notranslate"><span class="pre">'\N{...}'</span></code> now resolve name aliases,
|
||
and <a class="reference internal" href="../library/unicodedata.html#unicodedata.lookup" title="unicodedata.lookup"><code class="xref py py-func docutils literal notranslate"><span class="pre">unicodedata.lookup()</span></code></a> resolves named sequences too.</p>
|
||
<p>(Contributed by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue12753">bpo-12753</a>.)</p>
|
||
</li>
|
||
<li><p>Unicode database updated to UCD version 6.1.0</p></li>
|
||
<li><p>Equality comparisons on <a class="reference internal" href="../library/stdtypes.html#range" title="range"><code class="xref py py-func docutils literal notranslate"><span class="pre">range()</span></code></a> objects now return a result reflecting
|
||
the equality of the underlying sequences generated by those range objects.
|
||
(<a class="reference external" href="https://bugs.python.org/issue13201">bpo-13201</a>)</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">count()</span></code>, <code class="docutils literal notranslate"><span class="pre">find()</span></code>, <code class="docutils literal notranslate"><span class="pre">rfind()</span></code>, <code class="docutils literal notranslate"><span class="pre">index()</span></code> and <code class="docutils literal notranslate"><span class="pre">rindex()</span></code>
|
||
methods of <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> objects now accept an
|
||
integer between 0 and 255 as their first argument.</p>
|
||
<p>(Contributed by Petri Lehtinen in <a class="reference external" href="https://bugs.python.org/issue12170">bpo-12170</a>.)</p>
|
||
</li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">rjust()</span></code>, <code class="docutils literal notranslate"><span class="pre">ljust()</span></code>, and <code class="docutils literal notranslate"><span class="pre">center()</span></code> methods of <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a>
|
||
and <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> now accept a <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> for the <code class="docutils literal notranslate"><span class="pre">fill</span></code>
|
||
argument. (Contributed by Petri Lehtinen in <a class="reference external" href="https://bugs.python.org/issue12380">bpo-12380</a>.)</p></li>
|
||
<li><p>New methods have been added to <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a>:
|
||
<code class="docutils literal notranslate"><span class="pre">copy()</span></code> and <code class="docutils literal notranslate"><span class="pre">clear()</span></code> (<a class="reference external" href="https://bugs.python.org/issue10516">bpo-10516</a>). Consequently,
|
||
<a class="reference internal" href="../library/collections.abc.html#collections.abc.MutableSequence" title="collections.abc.MutableSequence"><code class="xref py py-class docutils literal notranslate"><span class="pre">MutableSequence</span></code></a> now also defines a
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">clear()</span></code> method (<a class="reference external" href="https://bugs.python.org/issue11388">bpo-11388</a>).</p></li>
|
||
<li><p>Raw bytes literals can now be written <code class="docutils literal notranslate"><span class="pre">rb"..."</span></code> as well as <code class="docutils literal notranslate"><span class="pre">br"..."</span></code>.</p>
|
||
<p>(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue13748">bpo-13748</a>.)</p>
|
||
</li>
|
||
<li><p><a class="reference internal" href="../library/stdtypes.html#dict.setdefault" title="dict.setdefault"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.setdefault()</span></code></a> now does only one lookup for the given key, making
|
||
it atomic when used with built-in types.</p>
|
||
<p>(Contributed by Filip Gruszczyński in <a class="reference external" href="https://bugs.python.org/issue13521">bpo-13521</a>.)</p>
|
||
</li>
|
||
<li><p>The error messages produced when a function call does not match the function
|
||
signature have been significantly improved.</p>
|
||
<p>(Contributed by Benjamin Peterson.)</p>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="a-finer-grained-import-lock">
|
||
<h2>A Finer-Grained Import Lock<a class="headerlink" href="#a-finer-grained-import-lock" title="Permalink to this headline">¶</a></h2>
|
||
<p>Previous versions of CPython have always relied on a global import lock.
|
||
This led to unexpected annoyances, such as deadlocks when importing a module
|
||
would trigger code execution in a different thread as a side-effect.
|
||
Clumsy workarounds were sometimes employed, such as the
|
||
<a class="reference internal" href="../c-api/import.html#c.PyImport_ImportModuleNoBlock" title="PyImport_ImportModuleNoBlock"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModuleNoBlock()</span></code></a> C API function.</p>
|
||
<p>In Python 3.3, importing a module takes a per-module lock. This correctly
|
||
serializes importation of a given module from multiple threads (preventing
|
||
the exposure of incompletely initialized modules), while eliminating the
|
||
aforementioned annoyances.</p>
|
||
<p>(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue9260">bpo-9260</a>.)</p>
|
||
</div>
|
||
<div class="section" id="builtin-functions-and-types">
|
||
<h2>Builtin functions and types<a class="headerlink" href="#builtin-functions-and-types" title="Permalink to this headline">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> gets a new <em>opener</em> parameter: the underlying file descriptor
|
||
for the file object is then obtained by calling <em>opener</em> with (<em>file</em>,
|
||
<em>flags</em>). It can be used to use custom flags like <a class="reference internal" href="../library/os.html#os.O_CLOEXEC" title="os.O_CLOEXEC"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.O_CLOEXEC</span></code></a> for
|
||
example. The <code class="docutils literal notranslate"><span class="pre">'x'</span></code> mode was added: open for exclusive creation, failing if
|
||
the file already exists.</p></li>
|
||
<li><p><a class="reference internal" href="../library/functions.html#print" title="print"><code class="xref py py-func docutils literal notranslate"><span class="pre">print()</span></code></a>: added the <em>flush</em> keyword argument. If the <em>flush</em> keyword
|
||
argument is true, the stream is forcibly flushed.</p></li>
|
||
<li><p><a class="reference internal" href="../library/functions.html#hash" title="hash"><code class="xref py py-func docutils literal notranslate"><span class="pre">hash()</span></code></a>: hash randomization is enabled by default, see
|
||
<a class="reference internal" href="../reference/datamodel.html#object.__hash__" title="object.__hash__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__hash__()</span></code></a> and <span class="target" id="index-22"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONHASHSEED"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHASHSEED</span></code></a>.</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> type gets a new <a class="reference internal" href="../library/stdtypes.html#str.casefold" title="str.casefold"><code class="xref py py-meth docutils literal notranslate"><span class="pre">casefold()</span></code></a> method: return a
|
||
casefolded copy of the string, casefolded strings may be used for caseless
|
||
matching. For example, <code class="docutils literal notranslate"><span class="pre">'ß'.casefold()</span></code> returns <code class="docutils literal notranslate"><span class="pre">'ss'</span></code>.</p></li>
|
||
<li><p>The sequence documentation has been substantially rewritten to better
|
||
explain the binary/text sequence distinction and to provide specific
|
||
documentation sections for the individual builtin sequence types
|
||
(<a class="reference external" href="https://bugs.python.org/issue4966">bpo-4966</a>).</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="new-modules">
|
||
<h2>New Modules<a class="headerlink" href="#new-modules" title="Permalink to this headline">¶</a></h2>
|
||
<div class="section" id="faulthandler">
|
||
<h3>faulthandler<a class="headerlink" href="#faulthandler" title="Permalink to this headline">¶</a></h3>
|
||
<p>This new debug module <a class="reference internal" href="../library/faulthandler.html#module-faulthandler" title="faulthandler: Dump the Python traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code></a> contains functions to dump Python tracebacks explicitly,
|
||
on a fault (a crash like a segmentation fault), after a timeout, or on a user
|
||
signal. Call <a class="reference internal" href="../library/faulthandler.html#faulthandler.enable" title="faulthandler.enable"><code class="xref py py-func docutils literal notranslate"><span class="pre">faulthandler.enable()</span></code></a> to install fault handlers for the
|
||
<code class="xref py py-const docutils literal notranslate"><span class="pre">SIGSEGV</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">SIGFPE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">SIGABRT</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">SIGBUS</span></code>, and
|
||
<code class="xref py py-const docutils literal notranslate"><span class="pre">SIGILL</span></code> signals. You can also enable them at startup by setting the
|
||
<span class="target" id="index-23"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONFAULTHANDLER"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONFAULTHANDLER</span></code></a> environment variable or by using <a class="reference internal" href="../using/cmdline.html#id5"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a>
|
||
<code class="docutils literal notranslate"><span class="pre">faulthandler</span></code> command line option.</p>
|
||
<p>Example of a segmentation fault on Linux:</p>
|
||
<div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> python -q -X faulthandler
|
||
<span class="gp">></span>>> import ctypes
|
||
<span class="gp">></span>>> ctypes.string_at<span class="o">(</span><span class="m">0</span><span class="o">)</span>
|
||
<span class="go">Fatal Python error: Segmentation fault</span>
|
||
|
||
<span class="go">Current thread 0x00007fb899f39700:</span>
|
||
<span class="go"> File "/home/python/cpython/Lib/ctypes/__init__.py", line 486 in string_at</span>
|
||
<span class="go"> File "<stdin>", line 1 in <module></span>
|
||
<span class="go">Segmentation fault</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="ipaddress">
|
||
<h3>ipaddress<a class="headerlink" href="#ipaddress" title="Permalink to this headline">¶</a></h3>
|
||
<p>The new <a class="reference internal" href="../library/ipaddress.html#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ipaddress</span></code></a> module provides tools for creating and manipulating
|
||
objects representing IPv4 and IPv6 addresses, networks and interfaces (i.e.
|
||
an IP address associated with a specific IP subnet).</p>
|
||
<p>(Contributed by Google and Peter Moody in <span class="target" id="index-24"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3144"><strong>PEP 3144</strong></a>.)</p>
|
||
</div>
|
||
<div class="section" id="lzma">
|
||
<h3>lzma<a class="headerlink" href="#lzma" title="Permalink to this headline">¶</a></h3>
|
||
<p>The newly-added <a class="reference internal" href="../library/lzma.html#module-lzma" title="lzma: A Python wrapper for the liblzma compression library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">lzma</span></code></a> module provides data compression and decompression
|
||
using the LZMA algorithm, including support for the <code class="docutils literal notranslate"><span class="pre">.xz</span></code> and <code class="docutils literal notranslate"><span class="pre">.lzma</span></code>
|
||
file formats.</p>
|
||
<p>(Contributed by Nadeem Vawda and Per Øyvind Karlsen in <a class="reference external" href="https://bugs.python.org/issue6715">bpo-6715</a>.)</p>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="improved-modules">
|
||
<h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Permalink to this headline">¶</a></h2>
|
||
<div class="section" id="abc">
|
||
<h3>abc<a class="headerlink" href="#abc" title="Permalink to this headline">¶</a></h3>
|
||
<p>Improved support for abstract base classes containing descriptors composed with
|
||
abstract methods. The recommended approach to declaring abstract descriptors is
|
||
now to provide <code class="xref py py-attr docutils literal notranslate"><span class="pre">__isabstractmethod__</span></code> as a dynamically updated
|
||
property. The built-in descriptors have been updated accordingly.</p>
|
||
<blockquote>
|
||
<div><ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/abc.html#abc.abstractproperty" title="abc.abstractproperty"><code class="xref py py-class docutils literal notranslate"><span class="pre">abc.abstractproperty</span></code></a> has been deprecated, use <a class="reference internal" href="../library/functions.html#property" title="property"><code class="xref py py-class docutils literal notranslate"><span class="pre">property</span></code></a>
|
||
with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.abstractmethod()</span></code></a> instead.</p></li>
|
||
<li><p><a class="reference internal" href="../library/abc.html#abc.abstractclassmethod" title="abc.abstractclassmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">abc.abstractclassmethod</span></code></a> has been deprecated, use
|
||
<a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">classmethod</span></code></a> with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.abstractmethod()</span></code></a> instead.</p></li>
|
||
<li><p><a class="reference internal" href="../library/abc.html#abc.abstractstaticmethod" title="abc.abstractstaticmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">abc.abstractstaticmethod</span></code></a> has been deprecated, use
|
||
<a class="reference internal" href="../library/functions.html#staticmethod" title="staticmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">staticmethod</span></code></a> with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.abstractmethod()</span></code></a> instead.</p></li>
|
||
</ul>
|
||
</div></blockquote>
|
||
<p>(Contributed by Darren Dale in <a class="reference external" href="https://bugs.python.org/issue11610">bpo-11610</a>.)</p>
|
||
<p><a class="reference internal" href="../library/abc.html#abc.ABCMeta.register" title="abc.ABCMeta.register"><code class="xref py py-meth docutils literal notranslate"><span class="pre">abc.ABCMeta.register()</span></code></a> now returns the registered subclass, which means
|
||
it can now be used as a class decorator (<a class="reference external" href="https://bugs.python.org/issue10868">bpo-10868</a>).</p>
|
||
</div>
|
||
<div class="section" id="array">
|
||
<h3>array<a class="headerlink" href="#array" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/array.html#module-array" title="array: Space efficient arrays of uniformly typed numeric values."><code class="xref py py-mod docutils literal notranslate"><span class="pre">array</span></code></a> module supports the <code class="xref c c-type docutils literal notranslate"><span class="pre">long</span> <span class="pre">long</span></code> type using <code class="docutils literal notranslate"><span class="pre">q</span></code> and
|
||
<code class="docutils literal notranslate"><span class="pre">Q</span></code> type codes.</p>
|
||
<p>(Contributed by Oren Tirosh and Hirokazu Yamamoto in <a class="reference external" href="https://bugs.python.org/issue1172711">bpo-1172711</a>.)</p>
|
||
</div>
|
||
<div class="section" id="base64">
|
||
<h3>base64<a class="headerlink" href="#base64" title="Permalink to this headline">¶</a></h3>
|
||
<p>ASCII-only Unicode strings are now accepted by the decoding functions of the
|
||
<a class="reference internal" href="../library/base64.html#module-base64" title="base64: RFC 3548: Base16, Base32, Base64 Data Encodings; Base85 and Ascii85"><code class="xref py py-mod docutils literal notranslate"><span class="pre">base64</span></code></a> modern interface. For example, <code class="docutils literal notranslate"><span class="pre">base64.b64decode('YWJj')</span></code>
|
||
returns <code class="docutils literal notranslate"><span class="pre">b'abc'</span></code>. (Contributed by Catalin Iacob in <a class="reference external" href="https://bugs.python.org/issue13641">bpo-13641</a>.)</p>
|
||
</div>
|
||
<div class="section" id="binascii">
|
||
<h3>binascii<a class="headerlink" href="#binascii" title="Permalink to this headline">¶</a></h3>
|
||
<p>In addition to the binary objects they normally accept, the <code class="docutils literal notranslate"><span class="pre">a2b_</span></code> functions
|
||
now all also accept ASCII-only strings as input. (Contributed by Antoine
|
||
Pitrou in <a class="reference external" href="https://bugs.python.org/issue13637">bpo-13637</a>.)</p>
|
||
</div>
|
||
<div class="section" id="bz2">
|
||
<h3>bz2<a class="headerlink" href="#bz2" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/bz2.html#module-bz2" title="bz2: Interfaces for bzip2 compression and decompression."><code class="xref py py-mod docutils literal notranslate"><span class="pre">bz2</span></code></a> module has been rewritten from scratch. In the process, several
|
||
new features have been added:</p>
|
||
<ul>
|
||
<li><p>New <a class="reference internal" href="../library/bz2.html#bz2.open" title="bz2.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">bz2.open()</span></code></a> function: open a bzip2-compressed file in binary or
|
||
text mode.</p></li>
|
||
<li><p><a class="reference internal" href="../library/bz2.html#bz2.BZ2File" title="bz2.BZ2File"><code class="xref py py-class docutils literal notranslate"><span class="pre">bz2.BZ2File</span></code></a> can now read from and write to arbitrary file-like
|
||
objects, by means of its constructor’s <em>fileobj</em> argument.</p>
|
||
<p>(Contributed by Nadeem Vawda in <a class="reference external" href="https://bugs.python.org/issue5863">bpo-5863</a>.)</p>
|
||
</li>
|
||
<li><p><a class="reference internal" href="../library/bz2.html#bz2.BZ2File" title="bz2.BZ2File"><code class="xref py py-class docutils literal notranslate"><span class="pre">bz2.BZ2File</span></code></a> and <a class="reference internal" href="../library/bz2.html#bz2.decompress" title="bz2.decompress"><code class="xref py py-func docutils literal notranslate"><span class="pre">bz2.decompress()</span></code></a> can now decompress
|
||
multi-stream inputs (such as those produced by the <strong class="program">pbzip2</strong> tool).
|
||
<a class="reference internal" href="../library/bz2.html#bz2.BZ2File" title="bz2.BZ2File"><code class="xref py py-class docutils literal notranslate"><span class="pre">bz2.BZ2File</span></code></a> can now also be used to create this type of file, using
|
||
the <code class="docutils literal notranslate"><span class="pre">'a'</span></code> (append) mode.</p>
|
||
<p>(Contributed by Nir Aides in <a class="reference external" href="https://bugs.python.org/issue1625">bpo-1625</a>.)</p>
|
||
</li>
|
||
<li><p><a class="reference internal" href="../library/bz2.html#bz2.BZ2File" title="bz2.BZ2File"><code class="xref py py-class docutils literal notranslate"><span class="pre">bz2.BZ2File</span></code></a> now implements all of the <a class="reference internal" href="../library/io.html#io.BufferedIOBase" title="io.BufferedIOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.BufferedIOBase</span></code></a> API,
|
||
except for the <code class="xref py py-meth docutils literal notranslate"><span class="pre">detach()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">truncate()</span></code> methods.</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="codecs">
|
||
<h3>codecs<a class="headerlink" href="#codecs" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/codecs.html#module-encodings.mbcs" title="encodings.mbcs: Windows ANSI codepage"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mbcs</span></code></a> codec has been rewritten to handle correctly
|
||
<code class="docutils literal notranslate"><span class="pre">replace</span></code> and <code class="docutils literal notranslate"><span class="pre">ignore</span></code> error handlers on all Windows versions. The
|
||
<a class="reference internal" href="../library/codecs.html#module-encodings.mbcs" title="encodings.mbcs: Windows ANSI codepage"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mbcs</span></code></a> codec now supports all error handlers, instead of only
|
||
<code class="docutils literal notranslate"><span class="pre">replace</span></code> to encode and <code class="docutils literal notranslate"><span class="pre">ignore</span></code> to decode.</p>
|
||
<p>A new Windows-only codec has been added: <code class="docutils literal notranslate"><span class="pre">cp65001</span></code> (<a class="reference external" href="https://bugs.python.org/issue13216">bpo-13216</a>). It is the
|
||
Windows code page 65001 (Windows UTF-8, <code class="docutils literal notranslate"><span class="pre">CP_UTF8</span></code>). For example, it is used
|
||
by <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code> if the console output code page is set to cp65001 (e.g., using
|
||
<code class="docutils literal notranslate"><span class="pre">chcp</span> <span class="pre">65001</span></code> command).</p>
|
||
<p>Multibyte CJK decoders now resynchronize faster. They only ignore the first
|
||
byte of an invalid byte sequence. For example, <code class="docutils literal notranslate"><span class="pre">b'\xff\n'.decode('gb2312',</span>
|
||
<span class="pre">'replace')</span></code> now returns a <code class="docutils literal notranslate"><span class="pre">\n</span></code> after the replacement character.</p>
|
||
<p>(<a class="reference external" href="https://bugs.python.org/issue12016">bpo-12016</a>)</p>
|
||
<p>Incremental CJK codec encoders are no longer reset at each call to their
|
||
encode() methods. For example:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">codecs</span>
|
||
<span class="gp">>>> </span><span class="n">encoder</span> <span class="o">=</span> <span class="n">codecs</span><span class="o">.</span><span class="n">getincrementalencoder</span><span class="p">(</span><span class="s1">'hz'</span><span class="p">)(</span><span class="s1">'strict'</span><span class="p">)</span>
|
||
<span class="gp">>>> </span><span class="sa">b</span><span class="s1">''</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">encoder</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="s1">'</span><span class="se">\u52ff\u65bd\u65bc\u4eba\u3002</span><span class="s1"> Bye.'</span><span class="p">)</span>
|
||
<span class="go">b'~{NpJ)l6HK!#~} Bye.'</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>This example gives <code class="docutils literal notranslate"><span class="pre">b'~{Np~}~{J)~}~{l6~}~{HK~}~{!#~}</span> <span class="pre">Bye.'</span></code> with older Python
|
||
versions.</p>
|
||
<p>(<a class="reference external" href="https://bugs.python.org/issue12100">bpo-12100</a>)</p>
|
||
<p>The <code class="docutils literal notranslate"><span class="pre">unicode_internal</span></code> codec has been deprecated.</p>
|
||
</div>
|
||
<div class="section" id="collections">
|
||
<h3>collections<a class="headerlink" href="#collections" title="Permalink to this headline">¶</a></h3>
|
||
<p>Addition of a new <a class="reference internal" href="../library/collections.html#collections.ChainMap" title="collections.ChainMap"><code class="xref py py-class docutils literal notranslate"><span class="pre">ChainMap</span></code></a> class to allow treating a
|
||
number of mappings as a single unit. (Written by Raymond Hettinger for
|
||
<a class="reference external" href="https://bugs.python.org/issue11089">bpo-11089</a>, made public in <a class="reference external" href="https://bugs.python.org/issue11297">bpo-11297</a>.)</p>
|
||
<p>The abstract base classes have been moved in a new <a class="reference internal" href="../library/collections.abc.html#module-collections.abc" title="collections.abc: Abstract base classes for containers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections.abc</span></code></a>
|
||
module, to better differentiate between the abstract and the concrete
|
||
collections classes. Aliases for ABCs are still present in the
|
||
<a class="reference internal" href="../library/collections.html#module-collections" title="collections: Container datatypes"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code></a> module to preserve existing imports. (<a class="reference external" href="https://bugs.python.org/issue11085">bpo-11085</a>)</p>
|
||
<p>The <a class="reference internal" href="../library/collections.html#collections.Counter" title="collections.Counter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Counter</span></code></a> class now supports the unary <code class="docutils literal notranslate"><span class="pre">+</span></code> and <code class="docutils literal notranslate"><span class="pre">-</span></code>
|
||
operators, as well as the in-place operators <code class="docutils literal notranslate"><span class="pre">+=</span></code>, <code class="docutils literal notranslate"><span class="pre">-=</span></code>, <code class="docutils literal notranslate"><span class="pre">|=</span></code>, and
|
||
<code class="docutils literal notranslate"><span class="pre">&=</span></code>. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue13121">bpo-13121</a>.)</p>
|
||
</div>
|
||
<div class="section" id="contextlib">
|
||
<h3>contextlib<a class="headerlink" href="#contextlib" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/contextlib.html#contextlib.ExitStack" title="contextlib.ExitStack"><code class="xref py py-class docutils literal notranslate"><span class="pre">ExitStack</span></code></a> now provides a solid foundation for
|
||
programmatic manipulation of context managers and similar cleanup
|
||
functionality. Unlike the previous <code class="docutils literal notranslate"><span class="pre">contextlib.nested</span></code> API (which was
|
||
deprecated and removed), the new API is designed to work correctly
|
||
regardless of whether context managers acquire their resources in
|
||
their <code class="docutils literal notranslate"><span class="pre">__init__</span></code> method (for example, file objects) or in their
|
||
<code class="docutils literal notranslate"><span class="pre">__enter__</span></code> method (for example, synchronisation objects from the
|
||
<a class="reference internal" href="../library/threading.html#module-threading" title="threading: Thread-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code></a> module).</p>
|
||
<p>(<a class="reference external" href="https://bugs.python.org/issue13585">bpo-13585</a>)</p>
|
||
</div>
|
||
<div class="section" id="crypt">
|
||
<h3>crypt<a class="headerlink" href="#crypt" title="Permalink to this headline">¶</a></h3>
|
||
<p>Addition of salt and modular crypt format (hashing method) and the <a class="reference internal" href="../library/crypt.html#crypt.mksalt" title="crypt.mksalt"><code class="xref py py-func docutils literal notranslate"><span class="pre">mksalt()</span></code></a>
|
||
function to the <a class="reference internal" href="../library/crypt.html#module-crypt" title="crypt: The crypt() function used to check Unix passwords. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">crypt</span></code></a> module.</p>
|
||
<p>(<a class="reference external" href="https://bugs.python.org/issue10924">bpo-10924</a>)</p>
|
||
</div>
|
||
<div class="section" id="curses">
|
||
<h3>curses<a class="headerlink" href="#curses" title="Permalink to this headline">¶</a></h3>
|
||
<blockquote>
|
||
<div><ul class="simple">
|
||
<li><p>If the <a class="reference internal" href="../library/curses.html#module-curses" title="curses: An interface to the curses library, providing portable terminal handling. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">curses</span></code></a> module is linked to the ncursesw library, use Unicode
|
||
functions when Unicode strings or characters are passed (e.g.
|
||
<code class="xref c c-func docutils literal notranslate"><span class="pre">waddwstr()</span></code>), and bytes functions otherwise (e.g. <code class="xref c c-func docutils literal notranslate"><span class="pre">waddstr()</span></code>).</p></li>
|
||
<li><p>Use the locale encoding instead of <code class="docutils literal notranslate"><span class="pre">utf-8</span></code> to encode Unicode strings.</p></li>
|
||
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">curses.window</span></code> has a new <a class="reference internal" href="../library/curses.html#curses.window.encoding" title="curses.window.encoding"><code class="xref py py-attr docutils literal notranslate"><span class="pre">curses.window.encoding</span></code></a> attribute.</p></li>
|
||
<li><p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">curses.window</span></code> class has a new <a class="reference internal" href="../library/curses.html#curses.window.get_wch" title="curses.window.get_wch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_wch()</span></code></a>
|
||
method to get a wide character</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/curses.html#module-curses" title="curses: An interface to the curses library, providing portable terminal handling. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">curses</span></code></a> module has a new <a class="reference internal" href="../library/curses.html#curses.unget_wch" title="curses.unget_wch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unget_wch()</span></code></a> function to
|
||
push a wide character so the next <a class="reference internal" href="../library/curses.html#curses.window.get_wch" title="curses.window.get_wch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_wch()</span></code></a> will return
|
||
it</p></li>
|
||
</ul>
|
||
</div></blockquote>
|
||
<p>(Contributed by Iñigo Serna in <a class="reference external" href="https://bugs.python.org/issue6755">bpo-6755</a>.)</p>
|
||
</div>
|
||
<div class="section" id="datetime">
|
||
<h3>datetime<a class="headerlink" href="#datetime" title="Permalink to this headline">¶</a></h3>
|
||
<blockquote>
|
||
<div><ul class="simple">
|
||
<li><p>Equality comparisons between naive and aware <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a>
|
||
instances now return <a class="reference internal" href="../library/constants.html#False" title="False"><code class="xref py py-const docutils literal notranslate"><span class="pre">False</span></code></a> instead of raising <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>
|
||
(<a class="reference external" href="https://bugs.python.org/issue15006">bpo-15006</a>).</p></li>
|
||
<li><p>New <a class="reference internal" href="../library/datetime.html#datetime.datetime.timestamp" title="datetime.datetime.timestamp"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.datetime.timestamp()</span></code></a> method: Return POSIX timestamp
|
||
corresponding to the <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> instance.</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/datetime.html#datetime.datetime.strftime" title="datetime.datetime.strftime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.datetime.strftime()</span></code></a> method supports formatting years
|
||
older than 1000.</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/datetime.html#datetime.datetime.astimezone" title="datetime.datetime.astimezone"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.datetime.astimezone()</span></code></a> method can now be
|
||
called without arguments to convert datetime instance to the system
|
||
timezone.</p></li>
|
||
</ul>
|
||
</div></blockquote>
|
||
</div>
|
||
<div class="section" id="decimal">
|
||
<span id="new-decimal"></span><h3>decimal<a class="headerlink" href="#decimal" title="Permalink to this headline">¶</a></h3>
|
||
<dl class="simple">
|
||
<dt><a class="reference external" href="https://bugs.python.org/issue7652">bpo-7652</a> - integrate fast native decimal arithmetic.</dt><dd><p>C-module and libmpdec written by Stefan Krah.</p>
|
||
</dd>
|
||
</dl>
|
||
<p>The new C version of the decimal module integrates the high speed libmpdec
|
||
library for arbitrary precision correctly-rounded decimal floating point
|
||
arithmetic. libmpdec conforms to IBM’s General Decimal Arithmetic Specification.</p>
|
||
<p>Performance gains range from 10x for database applications to 100x for
|
||
numerically intensive applications. These numbers are expected gains
|
||
for standard precisions used in decimal floating point arithmetic. Since
|
||
the precision is user configurable, the exact figures may vary. For example,
|
||
in integer bignum arithmetic the differences can be significantly higher.</p>
|
||
<p>The following table is meant as an illustration. Benchmarks are available
|
||
at <a class="reference external" href="http://www.bytereef.org/mpdecimal/quickstart.html">http://www.bytereef.org/mpdecimal/quickstart.html</a>.</p>
|
||
<blockquote>
|
||
<div><table class="docutils align-center">
|
||
<colgroup>
|
||
<col style="width: 18%" />
|
||
<col style="width: 27%" />
|
||
<col style="width: 29%" />
|
||
<col style="width: 27%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"></th>
|
||
<th class="head"><p>decimal.py</p></th>
|
||
<th class="head"><p>_decimal</p></th>
|
||
<th class="head"><p>speedup</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>pi</p></td>
|
||
<td><p>42.02s</p></td>
|
||
<td><p>0.345s</p></td>
|
||
<td><p>120x</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>telco</p></td>
|
||
<td><p>172.19s</p></td>
|
||
<td><p>5.68s</p></td>
|
||
<td><p>30x</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p>psycopg</p></td>
|
||
<td><p>3.57s</p></td>
|
||
<td><p>0.29s</p></td>
|
||
<td><p>12x</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div></blockquote>
|
||
<div class="section" id="id1">
|
||
<h4>Features<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h4>
|
||
<ul class="simple">
|
||
<li><p>The <a class="reference internal" href="../library/decimal.html#decimal.FloatOperation" title="decimal.FloatOperation"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FloatOperation</span></code></a> signal optionally enables stricter
|
||
semantics for mixing floats and Decimals.</p></li>
|
||
<li><p>If Python is compiled without threads, the C version automatically
|
||
disables the expensive thread local context machinery. In this case,
|
||
the variable <a class="reference internal" href="../library/decimal.html#decimal.HAVE_THREADS" title="decimal.HAVE_THREADS"><code class="xref py py-data docutils literal notranslate"><span class="pre">HAVE_THREADS</span></code></a> is set to <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="id2">
|
||
<h4>API changes<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h4>
|
||
<ul>
|
||
<li><p>The C module has the following context limits, depending on the machine
|
||
architecture:</p>
|
||
<blockquote>
|
||
<div><table class="docutils align-center">
|
||
<colgroup>
|
||
<col style="width: 27%" />
|
||
<col style="width: 30%" />
|
||
<col style="width: 43%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"></th>
|
||
<th class="head"><p>32-bit</p></th>
|
||
<th class="head"><p>64-bit</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">MAX_PREC</span></code></p></td>
|
||
<td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">425000000</span></code></p></td>
|
||
<td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">999999999999999999</span></code></p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">MAX_EMAX</span></code></p></td>
|
||
<td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">425000000</span></code></p></td>
|
||
<td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">999999999999999999</span></code></p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">MIN_EMIN</span></code></p></td>
|
||
<td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">-425000000</span></code></p></td>
|
||
<td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">-999999999999999999</span></code></p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div></blockquote>
|
||
</li>
|
||
<li><p>In the context templates (<a class="reference internal" href="../library/decimal.html#decimal.DefaultContext" title="decimal.DefaultContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">DefaultContext</span></code></a>,
|
||
<a class="reference internal" href="../library/decimal.html#decimal.BasicContext" title="decimal.BasicContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">BasicContext</span></code></a> and <a class="reference internal" href="../library/decimal.html#decimal.ExtendedContext" title="decimal.ExtendedContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ExtendedContext</span></code></a>)
|
||
the magnitude of <code class="xref py py-attr docutils literal notranslate"><span class="pre">Emax</span></code> and
|
||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">Emin</span></code> has changed to <code class="xref py py-const docutils literal notranslate"><span class="pre">999999</span></code>.</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">Decimal</span></code></a> constructor in decimal.py does not observe
|
||
the context limits and converts values with arbitrary exponents or precision
|
||
exactly. Since the C version has internal limits, the following scheme is
|
||
used: If possible, values are converted exactly, otherwise
|
||
<a class="reference internal" href="../library/decimal.html#decimal.InvalidOperation" title="decimal.InvalidOperation"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidOperation</span></code></a> is raised and the result is NaN. In the
|
||
latter case it is always possible to use <a class="reference internal" href="../library/decimal.html#decimal.Context.create_decimal" title="decimal.Context.create_decimal"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_decimal()</span></code></a>
|
||
in order to obtain a rounded or inexact value.</p></li>
|
||
<li><p>The power function in decimal.py is always correctly-rounded. In the
|
||
C version, it is defined in terms of the correctly-rounded
|
||
<a class="reference internal" href="../library/decimal.html#decimal.Decimal.exp" title="decimal.Decimal.exp"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exp()</span></code></a> and <a class="reference internal" href="../library/decimal.html#decimal.Decimal.ln" title="decimal.Decimal.ln"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ln()</span></code></a> functions,
|
||
but the final result is only “almost always correctly rounded”.</p></li>
|
||
<li><p>In the C version, the context dictionary containing the signals is a
|
||
<a class="reference internal" href="../library/collections.abc.html#collections.abc.MutableMapping" title="collections.abc.MutableMapping"><code class="xref py py-class docutils literal notranslate"><span class="pre">MutableMapping</span></code></a>. For speed reasons,
|
||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">flags</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">traps</span></code> always
|
||
refer to the same <a class="reference internal" href="../library/collections.abc.html#collections.abc.MutableMapping" title="collections.abc.MutableMapping"><code class="xref py py-class docutils literal notranslate"><span class="pre">MutableMapping</span></code></a> that the context
|
||
was initialized with. If a new signal dictionary is assigned,
|
||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">flags</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">traps</span></code>
|
||
are updated with the new values, but they do not reference the RHS
|
||
dictionary.</p></li>
|
||
<li><p>Pickling a <a class="reference internal" href="../library/decimal.html#decimal.Context" title="decimal.Context"><code class="xref py py-class docutils literal notranslate"><span class="pre">Context</span></code></a> produces a different output in order
|
||
to have a common interchange format for the Python and C versions.</p></li>
|
||
<li><p>The order of arguments in the <a class="reference internal" href="../library/decimal.html#decimal.Context" title="decimal.Context"><code class="xref py py-class docutils literal notranslate"><span class="pre">Context</span></code></a> constructor has been
|
||
changed to match the order displayed by <a class="reference internal" href="../library/functions.html#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a>.</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">watchexp</span></code> parameter in the <a class="reference internal" href="../library/decimal.html#decimal.Decimal.quantize" title="decimal.Decimal.quantize"><code class="xref py py-meth docutils literal notranslate"><span class="pre">quantize()</span></code></a> method
|
||
is deprecated.</p></li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="email">
|
||
<span id="new-email"></span><h3>email<a class="headerlink" href="#email" title="Permalink to this headline">¶</a></h3>
|
||
<div class="section" id="policy-framework">
|
||
<h4>Policy Framework<a class="headerlink" href="#policy-framework" title="Permalink to this headline">¶</a></h4>
|
||
<p>The email package now has a <a class="reference internal" href="../library/email.policy.html#module-email.policy" title="email.policy: Controlling the parsing and generating of messages"><code class="xref py py-mod docutils literal notranslate"><span class="pre">policy</span></code></a> framework. A
|
||
<a class="reference internal" href="../library/email.policy.html#email.policy.Policy" title="email.policy.Policy"><code class="xref py py-class docutils literal notranslate"><span class="pre">Policy</span></code></a> is an object with several methods and properties
|
||
that control how the email package behaves. The primary policy for Python 3.3
|
||
is the <a class="reference internal" href="../library/email.policy.html#email.policy.Compat32" title="email.policy.Compat32"><code class="xref py py-class docutils literal notranslate"><span class="pre">Compat32</span></code></a> policy, which provides backward
|
||
compatibility with the email package in Python 3.2. A <code class="docutils literal notranslate"><span class="pre">policy</span></code> can be
|
||
specified when an email message is parsed by a <a class="reference internal" href="../library/email.parser.html#module-email.parser" title="email.parser: Parse flat text email messages to produce a message object structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">parser</span></code></a>, or when a
|
||
<a class="reference internal" href="../library/email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> object is created, or when an email is
|
||
serialized using a <a class="reference internal" href="../library/email.generator.html#module-email.generator" title="email.generator: Generate flat text email messages from a message structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">generator</span></code></a>. Unless overridden, a policy passed
|
||
to a <code class="docutils literal notranslate"><span class="pre">parser</span></code> is inherited by all the <code class="docutils literal notranslate"><span class="pre">Message</span></code> object and sub-objects
|
||
created by the <code class="docutils literal notranslate"><span class="pre">parser</span></code>. By default a <code class="docutils literal notranslate"><span class="pre">generator</span></code> will use the policy of
|
||
the <code class="docutils literal notranslate"><span class="pre">Message</span></code> object it is serializing. The default policy is
|
||
<a class="reference internal" href="../library/email.policy.html#email.policy.compat32" title="email.policy.compat32"><code class="xref py py-data docutils literal notranslate"><span class="pre">compat32</span></code></a>.</p>
|
||
<p>The minimum set of controls implemented by all <code class="docutils literal notranslate"><span class="pre">policy</span></code> objects are:</p>
|
||
<blockquote>
|
||
<div><table class="docutils align-center">
|
||
<colgroup>
|
||
<col style="width: 21%" />
|
||
<col style="width: 79%" />
|
||
</colgroup>
|
||
<tbody>
|
||
<tr class="row-odd"><td><p>max_line_length</p></td>
|
||
<td><p>The maximum length, excluding the linesep character(s),
|
||
individual lines may have when a <code class="docutils literal notranslate"><span class="pre">Message</span></code> is
|
||
serialized. Defaults to 78.</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p>linesep</p></td>
|
||
<td><p>The character used to separate individual lines when a
|
||
<code class="docutils literal notranslate"><span class="pre">Message</span></code> is serialized. Defaults to <code class="docutils literal notranslate"><span class="pre">\n</span></code>.</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>cte_type</p></td>
|
||
<td><p><code class="docutils literal notranslate"><span class="pre">7bit</span></code> or <code class="docutils literal notranslate"><span class="pre">8bit</span></code>. <code class="docutils literal notranslate"><span class="pre">8bit</span></code> applies only to a
|
||
<code class="docutils literal notranslate"><span class="pre">Bytes</span></code> <code class="docutils literal notranslate"><span class="pre">generator</span></code>, and means that non-ASCII may
|
||
be used where allowed by the protocol (or where it
|
||
exists in the original input).</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p>raise_on_defect</p></td>
|
||
<td><p>Causes a <code class="docutils literal notranslate"><span class="pre">parser</span></code> to raise error when defects are
|
||
encountered instead of adding them to the <code class="docutils literal notranslate"><span class="pre">Message</span></code>
|
||
object’s <code class="docutils literal notranslate"><span class="pre">defects</span></code> list.</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div></blockquote>
|
||
<p>A new policy instance, with new settings, is created using the
|
||
<a class="reference internal" href="../library/email.policy.html#email.policy.Policy.clone" title="email.policy.Policy.clone"><code class="xref py py-meth docutils literal notranslate"><span class="pre">clone()</span></code></a> method of policy objects. <code class="docutils literal notranslate"><span class="pre">clone</span></code> takes
|
||
any of the above controls as keyword arguments. Any control not specified in
|
||
the call retains its default value. Thus you can create a policy that uses
|
||
<code class="docutils literal notranslate"><span class="pre">\r\n</span></code> linesep characters like this:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">mypolicy</span> <span class="o">=</span> <span class="n">compat32</span><span class="o">.</span><span class="n">clone</span><span class="p">(</span><span class="n">linesep</span><span class="o">=</span><span class="s1">'</span><span class="se">\r\n</span><span class="s1">'</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Policies can be used to make the generation of messages in the format needed by
|
||
your application simpler. Instead of having to remember to specify
|
||
<code class="docutils literal notranslate"><span class="pre">linesep='\r\n'</span></code> in all the places you call a <code class="docutils literal notranslate"><span class="pre">generator</span></code>, you can specify
|
||
it once, when you set the policy used by the <code class="docutils literal notranslate"><span class="pre">parser</span></code> or the <code class="docutils literal notranslate"><span class="pre">Message</span></code>,
|
||
whichever your program uses to create <code class="docutils literal notranslate"><span class="pre">Message</span></code> objects. On the other hand,
|
||
if you need to generate messages in multiple forms, you can still specify the
|
||
parameters in the appropriate <code class="docutils literal notranslate"><span class="pre">generator</span></code> call. Or you can have custom
|
||
policy instances for your different cases, and pass those in when you create
|
||
the <code class="docutils literal notranslate"><span class="pre">generator</span></code>.</p>
|
||
</div>
|
||
<div class="section" id="provisional-policy-with-new-header-api">
|
||
<h4>Provisional Policy with New Header API<a class="headerlink" href="#provisional-policy-with-new-header-api" title="Permalink to this headline">¶</a></h4>
|
||
<p>While the policy framework is worthwhile all by itself, the main motivation for
|
||
introducing it is to allow the creation of new policies that implement new
|
||
features for the email package in a way that maintains backward compatibility
|
||
for those who do not use the new policies. Because the new policies introduce a
|
||
new API, we are releasing them in Python 3.3 as a <a class="reference internal" href="../glossary.html#term-provisional-package"><span class="xref std std-term">provisional policy</span></a>. Backwards incompatible changes (up to and including
|
||
removal of the code) may occur if deemed necessary by the core developers.</p>
|
||
<p>The new policies are instances of <a class="reference internal" href="../library/email.policy.html#email.policy.EmailPolicy" title="email.policy.EmailPolicy"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailPolicy</span></code></a>,
|
||
and add the following additional controls:</p>
|
||
<blockquote>
|
||
<div><table class="docutils align-center">
|
||
<colgroup>
|
||
<col style="width: 21%" />
|
||
<col style="width: 79%" />
|
||
</colgroup>
|
||
<tbody>
|
||
<tr class="row-odd"><td><p>refold_source</p></td>
|
||
<td><p>Controls whether or not headers parsed by a
|
||
<a class="reference internal" href="../library/email.parser.html#module-email.parser" title="email.parser: Parse flat text email messages to produce a message object structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">parser</span></code></a> are refolded by the
|
||
<a class="reference internal" href="../library/email.generator.html#module-email.generator" title="email.generator: Generate flat text email messages from a message structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">generator</span></code></a>. It can be <code class="docutils literal notranslate"><span class="pre">none</span></code>, <code class="docutils literal notranslate"><span class="pre">long</span></code>,
|
||
or <code class="docutils literal notranslate"><span class="pre">all</span></code>. The default is <code class="docutils literal notranslate"><span class="pre">long</span></code>, which means that
|
||
source headers with a line longer than
|
||
<code class="docutils literal notranslate"><span class="pre">max_line_length</span></code> get refolded. <code class="docutils literal notranslate"><span class="pre">none</span></code> means no
|
||
line get refolded, and <code class="docutils literal notranslate"><span class="pre">all</span></code> means that all lines
|
||
get refolded.</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p>header_factory</p></td>
|
||
<td><p>A callable that take a <code class="docutils literal notranslate"><span class="pre">name</span></code> and <code class="docutils literal notranslate"><span class="pre">value</span></code> and
|
||
produces a custom header object.</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div></blockquote>
|
||
<p>The <code class="docutils literal notranslate"><span class="pre">header_factory</span></code> is the key to the new features provided by the new
|
||
policies. When one of the new policies is used, any header retrieved from
|
||
a <code class="docutils literal notranslate"><span class="pre">Message</span></code> object is an object produced by the <code class="docutils literal notranslate"><span class="pre">header_factory</span></code>, and any
|
||
time you set a header on a <code class="docutils literal notranslate"><span class="pre">Message</span></code> it becomes an object produced by
|
||
<code class="docutils literal notranslate"><span class="pre">header_factory</span></code>. All such header objects have a <code class="docutils literal notranslate"><span class="pre">name</span></code> attribute equal
|
||
to the header name. Address and Date headers have additional attributes
|
||
that give you access to the parsed data of the header. This means you can now
|
||
do things like this:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">m</span> <span class="o">=</span> <span class="n">Message</span><span class="p">(</span><span class="n">policy</span><span class="o">=</span><span class="n">SMTP</span><span class="p">)</span>
|
||
<span class="gp">>>> </span><span class="n">m</span><span class="p">[</span><span class="s1">'To'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'Éric <foo@example.com>'</span>
|
||
<span class="gp">>>> </span><span class="n">m</span><span class="p">[</span><span class="s1">'to'</span><span class="p">]</span>
|
||
<span class="go">'Éric <foo@example.com>'</span>
|
||
<span class="gp">>>> </span><span class="n">m</span><span class="p">[</span><span class="s1">'to'</span><span class="p">]</span><span class="o">.</span><span class="n">addresses</span>
|
||
<span class="go">(Address(display_name='Éric', username='foo', domain='example.com'),)</span>
|
||
<span class="gp">>>> </span><span class="n">m</span><span class="p">[</span><span class="s1">'to'</span><span class="p">]</span><span class="o">.</span><span class="n">addresses</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">username</span>
|
||
<span class="go">'foo'</span>
|
||
<span class="gp">>>> </span><span class="n">m</span><span class="p">[</span><span class="s1">'to'</span><span class="p">]</span><span class="o">.</span><span class="n">addresses</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">display_name</span>
|
||
<span class="go">'Éric'</span>
|
||
<span class="gp">>>> </span><span class="n">m</span><span class="p">[</span><span class="s1">'Date'</span><span class="p">]</span> <span class="o">=</span> <span class="n">email</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">localtime</span><span class="p">()</span>
|
||
<span class="gp">>>> </span><span class="n">m</span><span class="p">[</span><span class="s1">'Date'</span><span class="p">]</span><span class="o">.</span><span class="n">datetime</span>
|
||
<span class="go">datetime.datetime(2012, 5, 25, 21, 39, 24, 465484, tzinfo=datetime.timezone(datetime.timedelta(-1, 72000), 'EDT'))</span>
|
||
<span class="gp">>>> </span><span class="n">m</span><span class="p">[</span><span class="s1">'Date'</span><span class="p">]</span>
|
||
<span class="go">'Fri, 25 May 2012 21:44:27 -0400'</span>
|
||
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
|
||
<span class="go">To: =?utf-8?q?=C3=89ric?= <foo@example.com></span>
|
||
<span class="go">Date: Fri, 25 May 2012 21:44:27 -0400</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>You will note that the unicode display name is automatically encoded as
|
||
<code class="docutils literal notranslate"><span class="pre">utf-8</span></code> when the message is serialized, but that when the header is accessed
|
||
directly, you get the unicode version. This eliminates any need to deal with
|
||
the <a class="reference internal" href="../library/email.header.html#module-email.header" title="email.header: Representing non-ASCII headers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.header</span></code></a> <a class="reference internal" href="../library/email.header.html#email.header.decode_header" title="email.header.decode_header"><code class="xref py py-meth docutils literal notranslate"><span class="pre">decode_header()</span></code></a> or
|
||
<a class="reference internal" href="../library/email.header.html#email.header.make_header" title="email.header.make_header"><code class="xref py py-meth docutils literal notranslate"><span class="pre">make_header()</span></code></a> functions.</p>
|
||
<p>You can also create addresses from parts:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">m</span><span class="p">[</span><span class="s1">'cc'</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">Group</span><span class="p">(</span><span class="s1">'pals'</span><span class="p">,</span> <span class="p">[</span><span class="n">Address</span><span class="p">(</span><span class="s1">'Bob'</span><span class="p">,</span> <span class="s1">'bob'</span><span class="p">,</span> <span class="s1">'example.com'</span><span class="p">),</span>
|
||
<span class="gp">... </span> <span class="n">Address</span><span class="p">(</span><span class="s1">'Sally'</span><span class="p">,</span> <span class="s1">'sally'</span><span class="p">,</span> <span class="s1">'example.com'</span><span class="p">)]),</span>
|
||
<span class="gp">... </span> <span class="n">Address</span><span class="p">(</span><span class="s1">'Bonzo'</span><span class="p">,</span> <span class="n">addr_spec</span><span class="o">=</span><span class="s1">'bonz@laugh.com'</span><span class="p">)]</span>
|
||
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
|
||
<span class="go">To: =?utf-8?q?=C3=89ric?= <foo@example.com></span>
|
||
<span class="go">Date: Fri, 25 May 2012 21:44:27 -0400</span>
|
||
<span class="go">cc: pals: Bob <bob@example.com>, Sally <sally@example.com>;, Bonzo <bonz@laugh.com></span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Decoding to unicode is done automatically:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">m2</span> <span class="o">=</span> <span class="n">message_from_string</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">m</span><span class="p">))</span>
|
||
<span class="gp">>>> </span><span class="n">m2</span><span class="p">[</span><span class="s1">'to'</span><span class="p">]</span>
|
||
<span class="go">'Éric <foo@example.com>'</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>When you parse a message, you can use the <code class="docutils literal notranslate"><span class="pre">addresses</span></code> and <code class="docutils literal notranslate"><span class="pre">groups</span></code>
|
||
attributes of the header objects to access the groups and individual
|
||
addresses:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">m2</span><span class="p">[</span><span class="s1">'cc'</span><span class="p">]</span><span class="o">.</span><span class="n">addresses</span>
|
||
<span class="go">(Address(display_name='Bob', username='bob', domain='example.com'), Address(display_name='Sally', username='sally', domain='example.com'), Address(display_name='Bonzo', username='bonz', domain='laugh.com'))</span>
|
||
<span class="gp">>>> </span><span class="n">m2</span><span class="p">[</span><span class="s1">'cc'</span><span class="p">]</span><span class="o">.</span><span class="n">groups</span>
|
||
<span class="go">(Group(display_name='pals', addresses=(Address(display_name='Bob', username='bob', domain='example.com'), Address(display_name='Sally', username='sally', domain='example.com')), Group(display_name=None, addresses=(Address(display_name='Bonzo', username='bonz', domain='laugh.com'),))</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>In summary, if you use one of the new policies, header manipulation works the
|
||
way it ought to: your application works with unicode strings, and the email
|
||
package transparently encodes and decodes the unicode to and from the RFC
|
||
standard Content Transfer Encodings.</p>
|
||
</div>
|
||
<div class="section" id="other-api-changes">
|
||
<h4>Other API Changes<a class="headerlink" href="#other-api-changes" title="Permalink to this headline">¶</a></h4>
|
||
<p>New <a class="reference internal" href="../library/email.parser.html#email.parser.BytesHeaderParser" title="email.parser.BytesHeaderParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">BytesHeaderParser</span></code></a>, added to the <a class="reference internal" href="../library/email.parser.html#module-email.parser" title="email.parser: Parse flat text email messages to produce a message object structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">parser</span></code></a>
|
||
module to complement <a class="reference internal" href="../library/email.parser.html#email.parser.HeaderParser" title="email.parser.HeaderParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HeaderParser</span></code></a> and complete the Bytes
|
||
API.</p>
|
||
<p>New utility functions:</p>
|
||
<blockquote>
|
||
<div><ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/email.utils.html#email.utils.format_datetime" title="email.utils.format_datetime"><code class="xref py py-func docutils literal notranslate"><span class="pre">format_datetime()</span></code></a>: given a <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a>,
|
||
produce a string formatted for use in an email header.</p></li>
|
||
<li><p><a class="reference internal" href="../library/email.utils.html#email.utils.parsedate_to_datetime" title="email.utils.parsedate_to_datetime"><code class="xref py py-func docutils literal notranslate"><span class="pre">parsedate_to_datetime()</span></code></a>: given a date string from
|
||
an email header, convert it into an aware <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a>,
|
||
or a naive <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> if the offset is <code class="docutils literal notranslate"><span class="pre">-0000</span></code>.</p></li>
|
||
<li><p><a class="reference internal" href="../library/email.utils.html#email.utils.localtime" title="email.utils.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a>: With no argument, returns the
|
||
current local time as an aware <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> using the local
|
||
<a class="reference internal" href="../library/datetime.html#datetime.timezone" title="datetime.timezone"><code class="xref py py-class docutils literal notranslate"><span class="pre">timezone</span></code></a>. Given an aware <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a>,
|
||
converts it into an aware <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> using the
|
||
local <a class="reference internal" href="../library/datetime.html#datetime.timezone" title="datetime.timezone"><code class="xref py py-class docutils literal notranslate"><span class="pre">timezone</span></code></a>.</p></li>
|
||
</ul>
|
||
</div></blockquote>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="ftplib">
|
||
<h3>ftplib<a class="headerlink" href="#ftplib" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/ftplib.html#ftplib.FTP" title="ftplib.FTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">ftplib.FTP</span></code></a> now accepts a <code class="docutils literal notranslate"><span class="pre">source_address</span></code> keyword argument to
|
||
specify the <code class="docutils literal notranslate"><span class="pre">(host,</span> <span class="pre">port)</span></code> to use as the source address in the bind call
|
||
when creating the outgoing socket. (Contributed by Giampaolo Rodolà
|
||
in <a class="reference external" href="https://bugs.python.org/issue8594">bpo-8594</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/ftplib.html#ftplib.FTP_TLS" title="ftplib.FTP_TLS"><code class="xref py py-class docutils literal notranslate"><span class="pre">FTP_TLS</span></code></a> class now provides a new
|
||
<a class="reference internal" href="../library/ftplib.html#ftplib.FTP_TLS.ccc" title="ftplib.FTP_TLS.ccc"><code class="xref py py-func docutils literal notranslate"><span class="pre">ccc()</span></code></a> function to revert control channel back to
|
||
plaintext. This can be useful to take advantage of firewalls that know how
|
||
to handle NAT with non-secure FTP without opening fixed ports. (Contributed
|
||
by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue12139">bpo-12139</a>.)</p></li>
|
||
<li><p>Added <a class="reference internal" href="../library/ftplib.html#ftplib.FTP.mlsd" title="ftplib.FTP.mlsd"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ftplib.FTP.mlsd()</span></code></a> method which provides a parsable directory
|
||
listing format and deprecates <a class="reference internal" href="../library/ftplib.html#ftplib.FTP.nlst" title="ftplib.FTP.nlst"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ftplib.FTP.nlst()</span></code></a> and
|
||
<a class="reference internal" href="../library/ftplib.html#ftplib.FTP.dir" title="ftplib.FTP.dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ftplib.FTP.dir()</span></code></a>. (Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue11072">bpo-11072</a>.)</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="functools">
|
||
<h3>functools<a class="headerlink" href="#functools" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/functools.html#functools.lru_cache" title="functools.lru_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.lru_cache()</span></code></a> decorator now accepts a <code class="docutils literal notranslate"><span class="pre">typed</span></code> keyword
|
||
argument (that defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code> to ensure that it caches values of
|
||
different types that compare equal in separate cache slots. (Contributed
|
||
by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue13227">bpo-13227</a>.)</p>
|
||
</div>
|
||
<div class="section" id="gc">
|
||
<h3>gc<a class="headerlink" href="#gc" title="Permalink to this headline">¶</a></h3>
|
||
<p>It is now possible to register callbacks invoked by the garbage collector
|
||
before and after collection using the new <a class="reference internal" href="../library/gc.html#gc.callbacks" title="gc.callbacks"><code class="xref py py-data docutils literal notranslate"><span class="pre">callbacks</span></code></a> list.</p>
|
||
</div>
|
||
<div class="section" id="hmac">
|
||
<h3>hmac<a class="headerlink" href="#hmac" title="Permalink to this headline">¶</a></h3>
|
||
<p>A new <a class="reference internal" href="../library/hmac.html#hmac.compare_digest" title="hmac.compare_digest"><code class="xref py py-func docutils literal notranslate"><span class="pre">compare_digest()</span></code></a> function has been added to prevent side
|
||
channel attacks on digests through timing analysis. (Contributed by Nick
|
||
Coghlan and Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue15061">bpo-15061</a>.)</p>
|
||
</div>
|
||
<div class="section" id="http">
|
||
<h3>http<a class="headerlink" href="#http" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/http.server.html#http.server.BaseHTTPRequestHandler" title="http.server.BaseHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">http.server.BaseHTTPRequestHandler</span></code></a> now buffers the headers and writes
|
||
them all at once when <a class="reference internal" href="../library/http.server.html#http.server.BaseHTTPRequestHandler.end_headers" title="http.server.BaseHTTPRequestHandler.end_headers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">end_headers()</span></code></a> is
|
||
called. A new method <a class="reference internal" href="../library/http.server.html#http.server.BaseHTTPRequestHandler.flush_headers" title="http.server.BaseHTTPRequestHandler.flush_headers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">flush_headers()</span></code></a>
|
||
can be used to directly manage when the accumulated headers are sent.
|
||
(Contributed by Andrew Schaaf in <a class="reference external" href="https://bugs.python.org/issue3709">bpo-3709</a>.)</p>
|
||
<p><a class="reference internal" href="../library/http.server.html#module-http.server" title="http.server: HTTP server and request handlers."><code class="xref py py-class docutils literal notranslate"><span class="pre">http.server</span></code></a> now produces valid <code class="docutils literal notranslate"><span class="pre">HTML</span> <span class="pre">4.01</span> <span class="pre">strict</span></code> output.
|
||
(Contributed by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue13295">bpo-13295</a>.)</p>
|
||
<p><a class="reference internal" href="../library/http.client.html#http.client.HTTPResponse" title="http.client.HTTPResponse"><code class="xref py py-class docutils literal notranslate"><span class="pre">http.client.HTTPResponse</span></code></a> now has a
|
||
<a class="reference internal" href="../library/http.client.html#http.client.HTTPResponse.readinto" title="http.client.HTTPResponse.readinto"><code class="xref py py-meth docutils literal notranslate"><span class="pre">readinto()</span></code></a> method, which means it can be used
|
||
as an <a class="reference internal" href="../library/io.html#io.RawIOBase" title="io.RawIOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.RawIOBase</span></code></a> class. (Contributed by John Kuhn in
|
||
<a class="reference external" href="https://bugs.python.org/issue13464">bpo-13464</a>.)</p>
|
||
</div>
|
||
<div class="section" id="html">
|
||
<h3>html<a class="headerlink" href="#html" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/html.parser.html#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">html.parser.HTMLParser</span></code></a> is now able to parse broken markup without
|
||
raising errors, therefore the <em>strict</em> argument of the constructor and the
|
||
<code class="xref py py-exc docutils literal notranslate"><span class="pre">HTMLParseError</span></code> exception are now deprecated.
|
||
The ability to parse broken markup is the result of a number of bug fixes that
|
||
are also available on the latest bug fix releases of Python 2.7/3.2.
|
||
(Contributed by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue15114">bpo-15114</a>, and <a class="reference external" href="https://bugs.python.org/issue14538">bpo-14538</a>,
|
||
<a class="reference external" href="https://bugs.python.org/issue13993">bpo-13993</a>, <a class="reference external" href="https://bugs.python.org/issue13960">bpo-13960</a>, <a class="reference external" href="https://bugs.python.org/issue13358">bpo-13358</a>, <a class="reference external" href="https://bugs.python.org/issue1745761">bpo-1745761</a>,
|
||
<a class="reference external" href="https://bugs.python.org/issue755670">bpo-755670</a>, <a class="reference external" href="https://bugs.python.org/issue13357">bpo-13357</a>, <a class="reference external" href="https://bugs.python.org/issue12629">bpo-12629</a>, <a class="reference external" href="https://bugs.python.org/issue1200313">bpo-1200313</a>,
|
||
<a class="reference external" href="https://bugs.python.org/issue670664">bpo-670664</a>, <a class="reference external" href="https://bugs.python.org/issue13273">bpo-13273</a>, <a class="reference external" href="https://bugs.python.org/issue12888">bpo-12888</a>, <a class="reference external" href="https://bugs.python.org/issue7311">bpo-7311</a>.)</p>
|
||
<p>A new <a class="reference internal" href="../library/html.entities.html#html.entities.html5" title="html.entities.html5"><code class="xref py py-data docutils literal notranslate"><span class="pre">html5</span></code></a> dictionary that maps HTML5 named character
|
||
references to the equivalent Unicode character(s) (e.g. <code class="docutils literal notranslate"><span class="pre">html5['gt;']</span> <span class="pre">==</span>
|
||
<span class="pre">'>'</span></code>) has been added to the <a class="reference internal" href="../library/html.entities.html#module-html.entities" title="html.entities: Definitions of HTML general entities."><code class="xref py py-mod docutils literal notranslate"><span class="pre">html.entities</span></code></a> module. The dictionary is
|
||
now also used by <a class="reference internal" href="../library/html.parser.html#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a>. (Contributed by Ezio
|
||
Melotti in <a class="reference external" href="https://bugs.python.org/issue11113">bpo-11113</a> and <a class="reference external" href="https://bugs.python.org/issue15156">bpo-15156</a>.)</p>
|
||
</div>
|
||
<div class="section" id="imaplib">
|
||
<h3>imaplib<a class="headerlink" href="#imaplib" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4_SSL" title="imaplib.IMAP4_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4_SSL</span></code></a> constructor now accepts an SSLContext
|
||
parameter to control parameters of the secure channel.</p>
|
||
<p>(Contributed by Sijin Joseph in <a class="reference external" href="https://bugs.python.org/issue8808">bpo-8808</a>.)</p>
|
||
</div>
|
||
<div class="section" id="inspect">
|
||
<h3>inspect<a class="headerlink" href="#inspect" title="Permalink to this headline">¶</a></h3>
|
||
<p>A new <a class="reference internal" href="../library/inspect.html#inspect.getclosurevars" title="inspect.getclosurevars"><code class="xref py py-func docutils literal notranslate"><span class="pre">getclosurevars()</span></code></a> function has been added. This function
|
||
reports the current binding of all names referenced from the function body and
|
||
where those names were resolved, making it easier to verify correct internal
|
||
state when testing code that relies on stateful closures.</p>
|
||
<p>(Contributed by Meador Inge and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue13062">bpo-13062</a>.)</p>
|
||
<p>A new <a class="reference internal" href="../library/inspect.html#inspect.getgeneratorlocals" title="inspect.getgeneratorlocals"><code class="xref py py-func docutils literal notranslate"><span class="pre">getgeneratorlocals()</span></code></a> function has been added. This
|
||
function reports the current binding of local variables in the generator’s
|
||
stack frame, making it easier to verify correct internal state when testing
|
||
generators.</p>
|
||
<p>(Contributed by Meador Inge in <a class="reference external" href="https://bugs.python.org/issue15153">bpo-15153</a>.)</p>
|
||
</div>
|
||
<div class="section" id="io">
|
||
<h3>io<a class="headerlink" href="#io" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/io.html#io.open" title="io.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> function has a new <code class="docutils literal notranslate"><span class="pre">'x'</span></code> mode that can be used to
|
||
exclusively create a new file, and raise a <a class="reference internal" href="../library/exceptions.html#FileExistsError" title="FileExistsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileExistsError</span></code></a> if the file
|
||
already exists. It is based on the C11 ‘x’ mode to fopen().</p>
|
||
<p>(Contributed by David Townshend in <a class="reference external" href="https://bugs.python.org/issue12760">bpo-12760</a>.)</p>
|
||
<p>The constructor of the <a class="reference internal" href="../library/io.html#io.TextIOWrapper" title="io.TextIOWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextIOWrapper</span></code></a> class has a new
|
||
<em>write_through</em> optional argument. If <em>write_through</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, calls to
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code> are guaranteed not to be buffered: any data
|
||
written on the <a class="reference internal" href="../library/io.html#io.TextIOWrapper" title="io.TextIOWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextIOWrapper</span></code></a> object is immediately handled to its
|
||
underlying binary buffer.</p>
|
||
</div>
|
||
<div class="section" id="itertools">
|
||
<h3>itertools<a class="headerlink" href="#itertools" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/itertools.html#itertools.accumulate" title="itertools.accumulate"><code class="xref py py-func docutils literal notranslate"><span class="pre">accumulate()</span></code></a> now takes an optional <code class="docutils literal notranslate"><span class="pre">func</span></code> argument for
|
||
providing a user-supplied binary function.</p>
|
||
</div>
|
||
<div class="section" id="logging">
|
||
<h3>logging<a class="headerlink" href="#logging" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/logging.html#logging.basicConfig" title="logging.basicConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">basicConfig()</span></code></a> function now supports an optional <code class="docutils literal notranslate"><span class="pre">handlers</span></code>
|
||
argument taking an iterable of handlers to be added to the root logger.</p>
|
||
<p>A class level attribute <code class="xref py py-attr docutils literal notranslate"><span class="pre">append_nul</span></code> has
|
||
been added to <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.SysLogHandler" title="logging.handlers.SysLogHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SysLogHandler</span></code></a> to allow control of the
|
||
appending of the <code class="docutils literal notranslate"><span class="pre">NUL</span></code> (<code class="docutils literal notranslate"><span class="pre">\000</span></code>) byte to syslog records, since for some
|
||
daemons it is required while for others it is passed through to the log.</p>
|
||
</div>
|
||
<div class="section" id="math">
|
||
<h3>math<a class="headerlink" href="#math" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/math.html#module-math" title="math: Mathematical functions (sin() etc.)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">math</span></code></a> module has a new function, <a class="reference internal" href="../library/math.html#math.log2" title="math.log2"><code class="xref py py-func docutils literal notranslate"><span class="pre">log2()</span></code></a>, which returns
|
||
the base-2 logarithm of <em>x</em>.</p>
|
||
<p>(Written by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue11888">bpo-11888</a>.)</p>
|
||
</div>
|
||
<div class="section" id="mmap">
|
||
<h3>mmap<a class="headerlink" href="#mmap" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/mmap.html#mmap.mmap.read" title="mmap.mmap.read"><code class="xref py py-meth docutils literal notranslate"><span class="pre">read()</span></code></a> method is now more compatible with other file-like
|
||
objects: if the argument is omitted or specified as <code class="docutils literal notranslate"><span class="pre">None</span></code>, it returns the
|
||
bytes from the current file position to the end of the mapping. (Contributed
|
||
by Petri Lehtinen in <a class="reference external" href="https://bugs.python.org/issue12021">bpo-12021</a>.)</p>
|
||
</div>
|
||
<div class="section" id="multiprocessing">
|
||
<h3>multiprocessing<a class="headerlink" href="#multiprocessing" title="Permalink to this headline">¶</a></h3>
|
||
<p>The new <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.connection.wait" title="multiprocessing.connection.wait"><code class="xref py py-func docutils literal notranslate"><span class="pre">multiprocessing.connection.wait()</span></code></a> function allows polling
|
||
multiple objects (such as connections, sockets and pipes) with a timeout.
|
||
(Contributed by Richard Oudkerk in <a class="reference external" href="https://bugs.python.org/issue12328">bpo-12328</a>.)</p>
|
||
<p><code class="xref py py-class docutils literal notranslate"><span class="pre">multiprocessing.Connection</span></code> objects can now be transferred over
|
||
multiprocessing connections.
|
||
(Contributed by Richard Oudkerk in <a class="reference external" href="https://bugs.python.org/issue4892">bpo-4892</a>.)</p>
|
||
<p><a class="reference internal" href="../library/multiprocessing.html#multiprocessing.Process" title="multiprocessing.Process"><code class="xref py py-class docutils literal notranslate"><span class="pre">multiprocessing.Process</span></code></a> now accepts a <code class="docutils literal notranslate"><span class="pre">daemon</span></code> keyword argument
|
||
to override the default behavior of inheriting the <code class="docutils literal notranslate"><span class="pre">daemon</span></code> flag from
|
||
the parent process (<a class="reference external" href="https://bugs.python.org/issue6064">bpo-6064</a>).</p>
|
||
<p>New attribute <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.Process.sentinel" title="multiprocessing.Process.sentinel"><code class="xref py py-data docutils literal notranslate"><span class="pre">multiprocessing.Process.sentinel</span></code></a> allows a
|
||
program to wait on multiple <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.Process" title="multiprocessing.Process"><code class="xref py py-class docutils literal notranslate"><span class="pre">Process</span></code></a> objects at one
|
||
time using the appropriate OS primitives (for example, <a class="reference internal" href="../library/select.html#module-select" title="select: Wait for I/O completion on multiple streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">select</span></code></a> on
|
||
posix systems).</p>
|
||
<p>New methods <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.pool.Pool.starmap" title="multiprocessing.pool.Pool.starmap"><code class="xref py py-meth docutils literal notranslate"><span class="pre">multiprocessing.pool.Pool.starmap()</span></code></a> and
|
||
<a class="reference internal" href="../library/multiprocessing.html#multiprocessing.pool.Pool.starmap_async" title="multiprocessing.pool.Pool.starmap_async"><code class="xref py py-meth docutils literal notranslate"><span class="pre">starmap_async()</span></code></a> provide
|
||
<a class="reference internal" href="../library/itertools.html#itertools.starmap" title="itertools.starmap"><code class="xref py py-func docutils literal notranslate"><span class="pre">itertools.starmap()</span></code></a> equivalents to the existing
|
||
<a class="reference internal" href="../library/multiprocessing.html#multiprocessing.pool.Pool.map" title="multiprocessing.pool.Pool.map"><code class="xref py py-meth docutils literal notranslate"><span class="pre">multiprocessing.pool.Pool.map()</span></code></a> and
|
||
<a class="reference internal" href="../library/multiprocessing.html#multiprocessing.pool.Pool.map_async" title="multiprocessing.pool.Pool.map_async"><code class="xref py py-meth docutils literal notranslate"><span class="pre">map_async()</span></code></a> functions. (Contributed by Hynek
|
||
Schlawack in <a class="reference external" href="https://bugs.python.org/issue12708">bpo-12708</a>.)</p>
|
||
</div>
|
||
<div class="section" id="nntplib">
|
||
<h3>nntplib<a class="headerlink" href="#nntplib" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/nntplib.html#nntplib.NNTP" title="nntplib.NNTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">nntplib.NNTP</span></code></a> class now supports the context management protocol to
|
||
unconditionally consume <a class="reference internal" href="../library/socket.html#socket.error" title="socket.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">socket.error</span></code></a> exceptions and to close the NNTP
|
||
connection when done:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">nntplib</span> <span class="k">import</span> <span class="n">NNTP</span>
|
||
<span class="gp">>>> </span><span class="k">with</span> <span class="n">NNTP</span><span class="p">(</span><span class="s1">'news.gmane.org'</span><span class="p">)</span> <span class="k">as</span> <span class="n">n</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="n">n</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="s1">'gmane.comp.python.committers'</span><span class="p">)</span>
|
||
<span class="gp">...</span>
|
||
<span class="go">('211 1755 1 1755 gmane.comp.python.committers', 1755, 1, 1755, 'gmane.comp.python.committers')</span>
|
||
<span class="go">>>></span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue9795">bpo-9795</a>.)</p>
|
||
</div>
|
||
<div class="section" id="os">
|
||
<h3>os<a class="headerlink" href="#os" title="Permalink to this headline">¶</a></h3>
|
||
<ul>
|
||
<li><p>The <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module has a new <a class="reference internal" href="../library/os.html#os.pipe2" title="os.pipe2"><code class="xref py py-func docutils literal notranslate"><span class="pre">pipe2()</span></code></a> function that makes it
|
||
possible to create a pipe with <a class="reference internal" href="../library/os.html#os.O_CLOEXEC" title="os.O_CLOEXEC"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_CLOEXEC</span></code></a> or
|
||
<a class="reference internal" href="../library/os.html#os.O_NONBLOCK" title="os.O_NONBLOCK"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_NONBLOCK</span></code></a> flags set atomically. This is especially useful to
|
||
avoid race conditions in multi-threaded programs.</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module has a new <a class="reference internal" href="../library/os.html#os.sendfile" title="os.sendfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">sendfile()</span></code></a> function which provides
|
||
an efficient “zero-copy” way for copying data from one file (or socket)
|
||
descriptor to another. The phrase “zero-copy” refers to the fact that all of
|
||
the copying of data between the two descriptors is done entirely by the
|
||
kernel, with no copying of data into userspace buffers. <a class="reference internal" href="../library/os.html#os.sendfile" title="os.sendfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">sendfile()</span></code></a>
|
||
can be used to efficiently copy data from a file on disk to a network socket,
|
||
e.g. for downloading a file.</p>
|
||
<p>(Patch submitted by Ross Lagerwall and Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue10882">bpo-10882</a>.)</p>
|
||
</li>
|
||
<li><p>To avoid race conditions like symlink attacks and issues with temporary
|
||
files and directories, it is more reliable (and also faster) to manipulate
|
||
file descriptors instead of file names. Python 3.3 enhances existing functions
|
||
and introduces new functions to work on file descriptors (<a class="reference external" href="https://bugs.python.org/issue4761">bpo-4761</a>,
|
||
<a class="reference external" href="https://bugs.python.org/issue10755">bpo-10755</a> and <a class="reference external" href="https://bugs.python.org/issue14626">bpo-14626</a>).</p>
|
||
<ul class="simple">
|
||
<li><p>The <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module has a new <a class="reference internal" href="../library/os.html#os.fwalk" title="os.fwalk"><code class="xref py py-func docutils literal notranslate"><span class="pre">fwalk()</span></code></a> function similar to
|
||
<a class="reference internal" href="../library/os.html#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">walk()</span></code></a> except that it also yields file descriptors referring to the
|
||
directories visited. This is especially useful to avoid symlink races.</p></li>
|
||
<li><p>The following functions get new optional <em>dir_fd</em> (<a class="reference internal" href="../library/os.html#dir-fd"><span class="std std-ref">paths relative to
|
||
directory descriptors</span></a>) and/or <em>follow_symlinks</em> (<a class="reference internal" href="../library/os.html#follow-symlinks"><span class="std std-ref">not
|
||
following symlinks</span></a>):
|
||
<a class="reference internal" href="../library/os.html#os.access" title="os.access"><code class="xref py py-func docutils literal notranslate"><span class="pre">access()</span></code></a>, <a class="reference internal" href="../library/os.html#os.chflags" title="os.chflags"><code class="xref py py-func docutils literal notranslate"><span class="pre">chflags()</span></code></a>, <a class="reference internal" href="../library/os.html#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">chmod()</span></code></a>, <a class="reference internal" href="../library/os.html#os.chown" title="os.chown"><code class="xref py py-func docutils literal notranslate"><span class="pre">chown()</span></code></a>,
|
||
<a class="reference internal" href="../library/os.html#os.link" title="os.link"><code class="xref py py-func docutils literal notranslate"><span class="pre">link()</span></code></a>, <a class="reference internal" href="../library/os.html#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">lstat()</span></code></a>, <a class="reference internal" href="../library/os.html#os.mkdir" title="os.mkdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">mkdir()</span></code></a>, <a class="reference internal" href="../library/os.html#os.mkfifo" title="os.mkfifo"><code class="xref py py-func docutils literal notranslate"><span class="pre">mkfifo()</span></code></a>,
|
||
<a class="reference internal" href="../library/os.html#os.mknod" title="os.mknod"><code class="xref py py-func docutils literal notranslate"><span class="pre">mknod()</span></code></a>, <a class="reference internal" href="../library/os.html#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a>, <a class="reference internal" href="../library/os.html#os.readlink" title="os.readlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">readlink()</span></code></a>, <a class="reference internal" href="../library/os.html#os.remove" title="os.remove"><code class="xref py py-func docutils literal notranslate"><span class="pre">remove()</span></code></a>,
|
||
<a class="reference internal" href="../library/os.html#os.rename" title="os.rename"><code class="xref py py-func docutils literal notranslate"><span class="pre">rename()</span></code></a>, <a class="reference internal" href="../library/os.html#os.replace" title="os.replace"><code class="xref py py-func docutils literal notranslate"><span class="pre">replace()</span></code></a>, <a class="reference internal" href="../library/os.html#os.rmdir" title="os.rmdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">rmdir()</span></code></a>, <a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">stat()</span></code></a>,
|
||
<a class="reference internal" href="../library/os.html#os.symlink" title="os.symlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">symlink()</span></code></a>, <a class="reference internal" href="../library/os.html#os.unlink" title="os.unlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">unlink()</span></code></a>, <a class="reference internal" href="../library/os.html#os.utime" title="os.utime"><code class="xref py py-func docutils literal notranslate"><span class="pre">utime()</span></code></a>. Platform
|
||
support for using these parameters can be checked via the sets
|
||
<a class="reference internal" href="../library/os.html#os.supports_dir_fd" title="os.supports_dir_fd"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.supports_dir_fd</span></code></a> and <code class="xref py py-data docutils literal notranslate"><span class="pre">os.supports_follows_symlinks</span></code>.</p></li>
|
||
<li><p>The following functions now support a file descriptor for their path argument:
|
||
<a class="reference internal" href="../library/os.html#os.chdir" title="os.chdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">chdir()</span></code></a>, <a class="reference internal" href="../library/os.html#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">chmod()</span></code></a>, <a class="reference internal" href="../library/os.html#os.chown" title="os.chown"><code class="xref py py-func docutils literal notranslate"><span class="pre">chown()</span></code></a>,
|
||
<a class="reference internal" href="../library/os.html#os.execve" title="os.execve"><code class="xref py py-func docutils literal notranslate"><span class="pre">execve()</span></code></a>, <a class="reference internal" href="../library/os.html#os.listdir" title="os.listdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">listdir()</span></code></a>, <a class="reference internal" href="../library/os.html#os.pathconf" title="os.pathconf"><code class="xref py py-func docutils literal notranslate"><span class="pre">pathconf()</span></code></a>, <a class="reference internal" href="../library/os.path.html#os.path.exists" title="os.path.exists"><code class="xref py py-func docutils literal notranslate"><span class="pre">exists()</span></code></a>,
|
||
<a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">stat()</span></code></a>, <a class="reference internal" href="../library/os.html#os.statvfs" title="os.statvfs"><code class="xref py py-func docutils literal notranslate"><span class="pre">statvfs()</span></code></a>, <a class="reference internal" href="../library/os.html#os.utime" title="os.utime"><code class="xref py py-func docutils literal notranslate"><span class="pre">utime()</span></code></a>. Platform support
|
||
for this can be checked via the <a class="reference internal" href="../library/os.html#os.supports_fd" title="os.supports_fd"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.supports_fd</span></code></a> set.</p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.access" title="os.access"><code class="xref py py-func docutils literal notranslate"><span class="pre">access()</span></code></a> accepts an <code class="docutils literal notranslate"><span class="pre">effective_ids</span></code> keyword argument to turn on
|
||
using the effective uid/gid rather than the real uid/gid in the access check.
|
||
Platform support for this can be checked via the
|
||
<a class="reference internal" href="../library/os.html#os.supports_effective_ids" title="os.supports_effective_ids"><code class="xref py py-data docutils literal notranslate"><span class="pre">supports_effective_ids</span></code></a> set.</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module has two new functions: <a class="reference internal" href="../library/os.html#os.getpriority" title="os.getpriority"><code class="xref py py-func docutils literal notranslate"><span class="pre">getpriority()</span></code></a> and
|
||
<a class="reference internal" href="../library/os.html#os.setpriority" title="os.setpriority"><code class="xref py py-func docutils literal notranslate"><span class="pre">setpriority()</span></code></a>. They can be used to get or set process
|
||
niceness/priority in a fashion similar to <a class="reference internal" href="../library/os.html#os.nice" title="os.nice"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.nice()</span></code></a> but extended to all
|
||
processes instead of just the current one.</p>
|
||
<p>(Patch submitted by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue10784">bpo-10784</a>.)</p>
|
||
</li>
|
||
<li><p>The new <a class="reference internal" href="../library/os.html#os.replace" title="os.replace"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.replace()</span></code></a> function allows cross-platform renaming of a
|
||
file with overwriting the destination. With <a class="reference internal" href="../library/os.html#os.rename" title="os.rename"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.rename()</span></code></a>, an existing
|
||
destination file is overwritten under POSIX, but raises an error under
|
||
Windows.
|
||
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue8828">bpo-8828</a>.)</p></li>
|
||
<li><p>The stat family of functions (<a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">stat()</span></code></a>, <a class="reference internal" href="../library/os.html#os.fstat" title="os.fstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">fstat()</span></code></a>,
|
||
and <a class="reference internal" href="../library/os.html#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">lstat()</span></code></a>) now support reading a file’s timestamps
|
||
with nanosecond precision. Symmetrically, <a class="reference internal" href="../library/os.html#os.utime" title="os.utime"><code class="xref py py-func docutils literal notranslate"><span class="pre">utime()</span></code></a>
|
||
can now write file timestamps with nanosecond precision. (Contributed by
|
||
Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue14127">bpo-14127</a>.)</p></li>
|
||
<li><p>The new <a class="reference internal" href="../library/os.html#os.get_terminal_size" title="os.get_terminal_size"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.get_terminal_size()</span></code></a> function queries the size of the
|
||
terminal attached to a file descriptor. See also
|
||
<a class="reference internal" href="../library/shutil.html#shutil.get_terminal_size" title="shutil.get_terminal_size"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.get_terminal_size()</span></code></a>.
|
||
(Contributed by Zbigniew Jędrzejewski-Szmek in <a class="reference external" href="https://bugs.python.org/issue13609">bpo-13609</a>.)</p></li>
|
||
</ul>
|
||
<ul class="simple">
|
||
<li><p>New functions to support Linux extended attributes (<a class="reference external" href="https://bugs.python.org/issue12720">bpo-12720</a>):
|
||
<a class="reference internal" href="../library/os.html#os.getxattr" title="os.getxattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">getxattr()</span></code></a>, <a class="reference internal" href="../library/os.html#os.listxattr" title="os.listxattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">listxattr()</span></code></a>, <a class="reference internal" href="../library/os.html#os.removexattr" title="os.removexattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">removexattr()</span></code></a>,
|
||
<a class="reference internal" href="../library/os.html#os.setxattr" title="os.setxattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">setxattr()</span></code></a>.</p></li>
|
||
<li><p>New interface to the scheduler. These functions
|
||
control how a process is allocated CPU time by the operating system. New
|
||
functions:
|
||
<a class="reference internal" href="../library/os.html#os.sched_get_priority_max" title="os.sched_get_priority_max"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_get_priority_max()</span></code></a>, <a class="reference internal" href="../library/os.html#os.sched_get_priority_min" title="os.sched_get_priority_min"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_get_priority_min()</span></code></a>,
|
||
<a class="reference internal" href="../library/os.html#os.sched_getaffinity" title="os.sched_getaffinity"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_getaffinity()</span></code></a>, <a class="reference internal" href="../library/os.html#os.sched_getparam" title="os.sched_getparam"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_getparam()</span></code></a>,
|
||
<a class="reference internal" href="../library/os.html#os.sched_getscheduler" title="os.sched_getscheduler"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_getscheduler()</span></code></a>, <a class="reference internal" href="../library/os.html#os.sched_rr_get_interval" title="os.sched_rr_get_interval"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_rr_get_interval()</span></code></a>,
|
||
<a class="reference internal" href="../library/os.html#os.sched_setaffinity" title="os.sched_setaffinity"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_setaffinity()</span></code></a>, <a class="reference internal" href="../library/os.html#os.sched_setparam" title="os.sched_setparam"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_setparam()</span></code></a>,
|
||
<a class="reference internal" href="../library/os.html#os.sched_setscheduler" title="os.sched_setscheduler"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_setscheduler()</span></code></a>, <a class="reference internal" href="../library/os.html#os.sched_yield" title="os.sched_yield"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_yield()</span></code></a>,</p></li>
|
||
<li><p>New functions to control the file system:</p>
|
||
<ul>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.posix_fadvise" title="os.posix_fadvise"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_fadvise()</span></code></a>: Announces an intention to access data in a
|
||
specific pattern thus allowing the kernel to make optimizations.</p></li>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.posix_fallocate" title="os.posix_fallocate"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_fallocate()</span></code></a>: Ensures that enough disk space is allocated
|
||
for a file.</p></li>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.sync" title="os.sync"><code class="xref py py-func docutils literal notranslate"><span class="pre">sync()</span></code></a>: Force write of everything to disk.</p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p>Additional new posix functions:</p>
|
||
<ul>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.lockf" title="os.lockf"><code class="xref py py-func docutils literal notranslate"><span class="pre">lockf()</span></code></a>: Apply, test or remove a POSIX lock on an open file descriptor.</p></li>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.pread" title="os.pread"><code class="xref py py-func docutils literal notranslate"><span class="pre">pread()</span></code></a>: Read from a file descriptor at an offset, the file
|
||
offset remains unchanged.</p></li>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.pwrite" title="os.pwrite"><code class="xref py py-func docutils literal notranslate"><span class="pre">pwrite()</span></code></a>: Write to a file descriptor from an offset, leaving
|
||
the file offset unchanged.</p></li>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.readv" title="os.readv"><code class="xref py py-func docutils literal notranslate"><span class="pre">readv()</span></code></a>: Read from a file descriptor into a number of writable buffers.</p></li>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.truncate" title="os.truncate"><code class="xref py py-func docutils literal notranslate"><span class="pre">truncate()</span></code></a>: Truncate the file corresponding to <em>path</em>, so that
|
||
it is at most <em>length</em> bytes in size.</p></li>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.waitid" title="os.waitid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitid()</span></code></a>: Wait for the completion of one or more child processes.</p></li>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.writev" title="os.writev"><code class="xref py py-func docutils literal notranslate"><span class="pre">writev()</span></code></a>: Write the contents of <em>buffers</em> to a file descriptor,
|
||
where <em>buffers</em> is an arbitrary sequence of buffers.</p></li>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.getgrouplist" title="os.getgrouplist"><code class="xref py py-func docutils literal notranslate"><span class="pre">getgrouplist()</span></code></a> (<a class="reference external" href="https://bugs.python.org/issue9344">bpo-9344</a>): Return list of group ids that
|
||
specified user belongs to.</p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.times" title="os.times"><code class="xref py py-func docutils literal notranslate"><span class="pre">times()</span></code></a> and <a class="reference internal" href="../library/os.html#os.uname" title="os.uname"><code class="xref py py-func docutils literal notranslate"><span class="pre">uname()</span></code></a>: Return type changed from a tuple to
|
||
a tuple-like object with named attributes.</p></li>
|
||
<li><p>Some platforms now support additional constants for the <a class="reference internal" href="../library/os.html#os.lseek" title="os.lseek"><code class="xref py py-func docutils literal notranslate"><span class="pre">lseek()</span></code></a>
|
||
function, such as <code class="docutils literal notranslate"><span class="pre">os.SEEK_HOLE</span></code> and <code class="docutils literal notranslate"><span class="pre">os.SEEK_DATA</span></code>.</p></li>
|
||
<li><p>New constants <a class="reference internal" href="../library/os.html#os.RTLD_LAZY" title="os.RTLD_LAZY"><code class="xref py py-data docutils literal notranslate"><span class="pre">RTLD_LAZY</span></code></a>, <a class="reference internal" href="../library/os.html#os.RTLD_NOW" title="os.RTLD_NOW"><code class="xref py py-data docutils literal notranslate"><span class="pre">RTLD_NOW</span></code></a>,
|
||
<a class="reference internal" href="../library/os.html#os.RTLD_GLOBAL" title="os.RTLD_GLOBAL"><code class="xref py py-data docutils literal notranslate"><span class="pre">RTLD_GLOBAL</span></code></a>, <a class="reference internal" href="../library/os.html#os.RTLD_LOCAL" title="os.RTLD_LOCAL"><code class="xref py py-data docutils literal notranslate"><span class="pre">RTLD_LOCAL</span></code></a>, <a class="reference internal" href="../library/os.html#os.RTLD_NODELETE" title="os.RTLD_NODELETE"><code class="xref py py-data docutils literal notranslate"><span class="pre">RTLD_NODELETE</span></code></a>,
|
||
<a class="reference internal" href="../library/os.html#os.RTLD_NOLOAD" title="os.RTLD_NOLOAD"><code class="xref py py-data docutils literal notranslate"><span class="pre">RTLD_NOLOAD</span></code></a>, and <a class="reference internal" href="../library/os.html#os.RTLD_DEEPBIND" title="os.RTLD_DEEPBIND"><code class="xref py py-data docutils literal notranslate"><span class="pre">RTLD_DEEPBIND</span></code></a> are available on
|
||
platforms that support them. These are for use with the
|
||
<a class="reference internal" href="../library/sys.html#sys.setdlopenflags" title="sys.setdlopenflags"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.setdlopenflags()</span></code></a> function, and supersede the similar constants
|
||
defined in <a class="reference internal" href="../library/ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code></a> and <code class="xref py py-mod docutils literal notranslate"><span class="pre">DLFCN</span></code>. (Contributed by Victor Stinner
|
||
in <a class="reference external" href="https://bugs.python.org/issue13226">bpo-13226</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.symlink" title="os.symlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.symlink()</span></code></a> now accepts (and ignores) the <code class="docutils literal notranslate"><span class="pre">target_is_directory</span></code>
|
||
keyword argument on non-Windows platforms, to ease cross-platform support.</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="pdb">
|
||
<h3>pdb<a class="headerlink" href="#pdb" title="Permalink to this headline">¶</a></h3>
|
||
<p>Tab-completion is now available not only for command names, but also their
|
||
arguments. For example, for the <code class="docutils literal notranslate"><span class="pre">break</span></code> command, function and file names
|
||
are completed.</p>
|
||
<p>(Contributed by Georg Brandl in <a class="reference external" href="https://bugs.python.org/issue14210">bpo-14210</a>)</p>
|
||
</div>
|
||
<div class="section" id="pickle">
|
||
<h3>pickle<a class="headerlink" href="#pickle" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/pickle.html#pickle.Pickler" title="pickle.Pickler"><code class="xref py py-class docutils literal notranslate"><span class="pre">pickle.Pickler</span></code></a> objects now have an optional
|
||
<a class="reference internal" href="../library/pickle.html#pickle.Pickler.dispatch_table" title="pickle.Pickler.dispatch_table"><code class="xref py py-attr docutils literal notranslate"><span class="pre">dispatch_table</span></code></a> attribute allowing per-pickler
|
||
reduction functions to be set.</p>
|
||
<p>(Contributed by Richard Oudkerk in <a class="reference external" href="https://bugs.python.org/issue14166">bpo-14166</a>.)</p>
|
||
</div>
|
||
<div class="section" id="pydoc">
|
||
<h3>pydoc<a class="headerlink" href="#pydoc" title="Permalink to this headline">¶</a></h3>
|
||
<p>The Tk GUI and the <code class="xref py py-func docutils literal notranslate"><span class="pre">serve()</span></code> function have been removed from the
|
||
<a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> module: <code class="docutils literal notranslate"><span class="pre">pydoc</span> <span class="pre">-g</span></code> and <code class="xref py py-func docutils literal notranslate"><span class="pre">serve()</span></code> have been deprecated
|
||
in Python 3.2.</p>
|
||
</div>
|
||
<div class="section" id="re">
|
||
<h3>re<a class="headerlink" href="#re" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> regular expressions now support <code class="docutils literal notranslate"><span class="pre">\u</span></code> and <code class="docutils literal notranslate"><span class="pre">\U</span></code> escapes.</p>
|
||
<p>(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue3665">bpo-3665</a>.)</p>
|
||
</div>
|
||
<div class="section" id="sched">
|
||
<h3>sched<a class="headerlink" href="#sched" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/sched.html#sched.scheduler.run" title="sched.scheduler.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">run()</span></code></a> now accepts a <em>blocking</em> parameter which when
|
||
set to false makes the method execute the scheduled events due to expire
|
||
soonest (if any) and then return immediately.
|
||
This is useful in case you want to use the <a class="reference internal" href="../library/sched.html#sched.scheduler" title="sched.scheduler"><code class="xref py py-class docutils literal notranslate"><span class="pre">scheduler</span></code></a> in
|
||
non-blocking applications. (Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue13449">bpo-13449</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/sched.html#sched.scheduler" title="sched.scheduler"><code class="xref py py-class docutils literal notranslate"><span class="pre">scheduler</span></code></a> class can now be safely used in multi-threaded
|
||
environments. (Contributed by Josiah Carlson and Giampaolo Rodolà in
|
||
<a class="reference external" href="https://bugs.python.org/issue8684">bpo-8684</a>.)</p></li>
|
||
<li><p><em>timefunc</em> and <em>delayfunct</em> parameters of <a class="reference internal" href="../library/sched.html#sched.scheduler" title="sched.scheduler"><code class="xref py py-class docutils literal notranslate"><span class="pre">scheduler</span></code></a> class
|
||
constructor are now optional and defaults to <a class="reference internal" href="../library/time.html#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.time()</span></code></a> and
|
||
<a class="reference internal" href="../library/time.html#time.sleep" title="time.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.sleep()</span></code></a> respectively. (Contributed by Chris Clark in
|
||
<a class="reference external" href="https://bugs.python.org/issue13245">bpo-13245</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/sched.html#sched.scheduler.enter" title="sched.scheduler.enter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enter()</span></code></a> and <a class="reference internal" href="../library/sched.html#sched.scheduler.enterabs" title="sched.scheduler.enterabs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enterabs()</span></code></a>
|
||
<em>argument</em> parameter is now optional. (Contributed by Chris Clark in
|
||
<a class="reference external" href="https://bugs.python.org/issue13245">bpo-13245</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/sched.html#sched.scheduler.enter" title="sched.scheduler.enter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enter()</span></code></a> and <a class="reference internal" href="../library/sched.html#sched.scheduler.enterabs" title="sched.scheduler.enterabs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enterabs()</span></code></a>
|
||
now accept a <em>kwargs</em> parameter. (Contributed by Chris Clark in
|
||
<a class="reference external" href="https://bugs.python.org/issue13245">bpo-13245</a>.)</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="select">
|
||
<h3>select<a class="headerlink" href="#select" title="Permalink to this headline">¶</a></h3>
|
||
<p>Solaris and derivative platforms have a new class <a class="reference internal" href="../library/select.html#select.devpoll" title="select.devpoll"><code class="xref py py-class docutils literal notranslate"><span class="pre">select.devpoll</span></code></a>
|
||
for high performance asynchronous sockets via <code class="file docutils literal notranslate"><span class="pre">/dev/poll</span></code>.
|
||
(Contributed by Jesús Cea Avión in <a class="reference external" href="https://bugs.python.org/issue6397">bpo-6397</a>.)</p>
|
||
</div>
|
||
<div class="section" id="shlex">
|
||
<h3>shlex<a class="headerlink" href="#shlex" title="Permalink to this headline">¶</a></h3>
|
||
<p>The previously undocumented helper function <code class="docutils literal notranslate"><span class="pre">quote</span></code> from the
|
||
<a class="reference internal" href="../library/pipes.html#module-pipes" title="pipes: A Python interface to Unix shell pipelines. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pipes</span></code></a> modules has been moved to the <a class="reference internal" href="../library/shlex.html#module-shlex" title="shlex: Simple lexical analysis for Unix shell-like languages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">shlex</span></code></a> module and
|
||
documented. <a class="reference internal" href="../library/shlex.html#shlex.quote" title="shlex.quote"><code class="xref py py-func docutils literal notranslate"><span class="pre">quote()</span></code></a> properly escapes all characters in a string
|
||
that might be otherwise given special meaning by the shell.</p>
|
||
</div>
|
||
<div class="section" id="shutil">
|
||
<h3>shutil<a class="headerlink" href="#shutil" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>New functions:</p>
|
||
<ul>
|
||
<li><p><a class="reference internal" href="../library/shutil.html#shutil.disk_usage" title="shutil.disk_usage"><code class="xref py py-func docutils literal notranslate"><span class="pre">disk_usage()</span></code></a>: provides total, used and free disk space
|
||
statistics. (Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue12442">bpo-12442</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/shutil.html#shutil.chown" title="shutil.chown"><code class="xref py py-func docutils literal notranslate"><span class="pre">chown()</span></code></a>: allows one to change user and/or group of the given
|
||
path also specifying the user/group names and not only their numeric
|
||
ids. (Contributed by Sandro Tosi in <a class="reference external" href="https://bugs.python.org/issue12191">bpo-12191</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/shutil.html#shutil.get_terminal_size" title="shutil.get_terminal_size"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.get_terminal_size()</span></code></a>: returns the size of the terminal window
|
||
to which the interpreter is attached. (Contributed by Zbigniew
|
||
Jędrzejewski-Szmek in <a class="reference external" href="https://bugs.python.org/issue13609">bpo-13609</a>.)</p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p><a class="reference internal" href="../library/shutil.html#shutil.copy2" title="shutil.copy2"><code class="xref py py-func docutils literal notranslate"><span class="pre">copy2()</span></code></a> and <a class="reference internal" href="../library/shutil.html#shutil.copystat" title="shutil.copystat"><code class="xref py py-func docutils literal notranslate"><span class="pre">copystat()</span></code></a> now preserve file
|
||
timestamps with nanosecond precision on platforms that support it.
|
||
They also preserve file “extended attributes” on Linux. (Contributed
|
||
by Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue14127">bpo-14127</a> and <a class="reference external" href="https://bugs.python.org/issue15238">bpo-15238</a>.)</p></li>
|
||
<li><p>Several functions now take an optional <code class="docutils literal notranslate"><span class="pre">symlinks</span></code> argument: when that
|
||
parameter is true, symlinks aren’t dereferenced and the operation instead
|
||
acts on the symlink itself (or creates one, if relevant).
|
||
(Contributed by Hynek Schlawack in <a class="reference external" href="https://bugs.python.org/issue12715">bpo-12715</a>.)</p></li>
|
||
<li><p>When copying files to a different file system, <a class="reference internal" href="../library/shutil.html#shutil.move" title="shutil.move"><code class="xref py py-func docutils literal notranslate"><span class="pre">move()</span></code></a> now
|
||
handles symlinks the way the posix <code class="docutils literal notranslate"><span class="pre">mv</span></code> command does, recreating the
|
||
symlink rather than copying the target file contents. (Contributed by
|
||
Jonathan Niehof in <a class="reference external" href="https://bugs.python.org/issue9993">bpo-9993</a>.) <a class="reference internal" href="../library/shutil.html#shutil.move" title="shutil.move"><code class="xref py py-func docutils literal notranslate"><span class="pre">move()</span></code></a> now also returns
|
||
the <code class="docutils literal notranslate"><span class="pre">dst</span></code> argument as its result.</p></li>
|
||
<li><p><a class="reference internal" href="../library/shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal notranslate"><span class="pre">rmtree()</span></code></a> is now resistant to symlink attacks on platforms
|
||
which support the new <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code> parameter in <a class="reference internal" href="../library/os.html#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.open()</span></code></a> and
|
||
<a class="reference internal" href="../library/os.html#os.unlink" title="os.unlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.unlink()</span></code></a>. (Contributed by Martin von Löwis and Hynek Schlawack
|
||
in <a class="reference external" href="https://bugs.python.org/issue4489">bpo-4489</a>.)</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="signal">
|
||
<h3>signal<a class="headerlink" href="#signal" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>The <a class="reference internal" href="../library/signal.html#module-signal" title="signal: Set handlers for asynchronous events."><code class="xref py py-mod docutils literal notranslate"><span class="pre">signal</span></code></a> module has new functions:</p>
|
||
<ul>
|
||
<li><p><a class="reference internal" href="../library/signal.html#signal.pthread_sigmask" title="signal.pthread_sigmask"><code class="xref py py-func docutils literal notranslate"><span class="pre">pthread_sigmask()</span></code></a>: fetch and/or change the signal mask of the
|
||
calling thread (Contributed by Jean-Paul Calderone in <a class="reference external" href="https://bugs.python.org/issue8407">bpo-8407</a>);</p></li>
|
||
<li><p><a class="reference internal" href="../library/signal.html#signal.pthread_kill" title="signal.pthread_kill"><code class="xref py py-func docutils literal notranslate"><span class="pre">pthread_kill()</span></code></a>: send a signal to a thread;</p></li>
|
||
<li><p><a class="reference internal" href="../library/signal.html#signal.sigpending" title="signal.sigpending"><code class="xref py py-func docutils literal notranslate"><span class="pre">sigpending()</span></code></a>: examine pending functions;</p></li>
|
||
<li><p><a class="reference internal" href="../library/signal.html#signal.sigwait" title="signal.sigwait"><code class="xref py py-func docutils literal notranslate"><span class="pre">sigwait()</span></code></a>: wait a signal;</p></li>
|
||
<li><p><a class="reference internal" href="../library/signal.html#signal.sigwaitinfo" title="signal.sigwaitinfo"><code class="xref py py-func docutils literal notranslate"><span class="pre">sigwaitinfo()</span></code></a>: wait for a signal, returning detailed
|
||
information about it;</p></li>
|
||
<li><p><a class="reference internal" href="../library/signal.html#signal.sigtimedwait" title="signal.sigtimedwait"><code class="xref py py-func docutils literal notranslate"><span class="pre">sigtimedwait()</span></code></a>: like <a class="reference internal" href="../library/signal.html#signal.sigwaitinfo" title="signal.sigwaitinfo"><code class="xref py py-func docutils literal notranslate"><span class="pre">sigwaitinfo()</span></code></a> but with a
|
||
timeout.</p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p>The signal handler writes the signal number as a single byte instead of
|
||
a nul byte into the wakeup file descriptor. So it is possible to wait more
|
||
than one signal and know which signals were raised.</p></li>
|
||
<li><p><a class="reference internal" href="../library/signal.html#signal.signal" title="signal.signal"><code class="xref py py-func docutils literal notranslate"><span class="pre">signal.signal()</span></code></a> and <a class="reference internal" href="../library/signal.html#signal.siginterrupt" title="signal.siginterrupt"><code class="xref py py-func docutils literal notranslate"><span class="pre">signal.siginterrupt()</span></code></a> raise an OSError,
|
||
instead of a RuntimeError: OSError has an errno attribute.</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="smtpd">
|
||
<h3>smtpd<a class="headerlink" href="#smtpd" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/smtpd.html#module-smtpd" title="smtpd: A SMTP server implementation in Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtpd</span></code></a> module now supports <span class="target" id="index-25"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5321.html"><strong>RFC 5321</strong></a> (extended SMTP) and <span class="target" id="index-26"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc1870.html"><strong>RFC 1870</strong></a>
|
||
(size extension). Per the standard, these extensions are enabled if and only
|
||
if the client initiates the session with an <code class="docutils literal notranslate"><span class="pre">EHLO</span></code> command.</p>
|
||
<p>(Initial <code class="docutils literal notranslate"><span class="pre">ELHO</span></code> support by Alberto Trevino. Size extension by Juhana
|
||
Jauhiainen. Substantial additional work on the patch contributed by Michele
|
||
Orrù and Dan Boswell. <a class="reference external" href="https://bugs.python.org/issue8739">bpo-8739</a>)</p>
|
||
</div>
|
||
<div class="section" id="smtplib">
|
||
<h3>smtplib<a class="headerlink" href="#smtplib" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP" title="smtplib.SMTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTP</span></code></a>, <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP_SSL" title="smtplib.SMTP_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTP_SSL</span></code></a>, and
|
||
<a class="reference internal" href="../library/smtplib.html#smtplib.LMTP" title="smtplib.LMTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">LMTP</span></code></a> classes now accept a <code class="docutils literal notranslate"><span class="pre">source_address</span></code> keyword argument
|
||
to specify the <code class="docutils literal notranslate"><span class="pre">(host,</span> <span class="pre">port)</span></code> to use as the source address in the bind call
|
||
when creating the outgoing socket. (Contributed by Paulo Scardine in
|
||
<a class="reference external" href="https://bugs.python.org/issue11281">bpo-11281</a>.)</p>
|
||
<p><a class="reference internal" href="../library/smtplib.html#smtplib.SMTP" title="smtplib.SMTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTP</span></code></a> now supports the context management protocol, allowing an
|
||
<code class="docutils literal notranslate"><span class="pre">SMTP</span></code> instance to be used in a <code class="docutils literal notranslate"><span class="pre">with</span></code> statement. (Contributed
|
||
by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue11289">bpo-11289</a>.)</p>
|
||
<p>The <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP_SSL" title="smtplib.SMTP_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTP_SSL</span></code></a> constructor and the <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP.starttls" title="smtplib.SMTP.starttls"><code class="xref py py-meth docutils literal notranslate"><span class="pre">starttls()</span></code></a>
|
||
method now accept an SSLContext parameter to control parameters of the secure
|
||
channel. (Contributed by Kasun Herath in <a class="reference external" href="https://bugs.python.org/issue8809">bpo-8809</a>.)</p>
|
||
</div>
|
||
<div class="section" id="socket">
|
||
<h3>socket<a class="headerlink" href="#socket" title="Permalink to this headline">¶</a></h3>
|
||
<ul>
|
||
<li><p>The <a class="reference internal" href="../library/socket.html#socket.socket" title="socket.socket"><code class="xref py py-class docutils literal notranslate"><span class="pre">socket</span></code></a> class now exposes additional methods to process
|
||
ancillary data when supported by the underlying platform:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/socket.html#socket.socket.sendmsg" title="socket.socket.sendmsg"><code class="xref py py-func docutils literal notranslate"><span class="pre">sendmsg()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/socket.html#socket.socket.recvmsg" title="socket.socket.recvmsg"><code class="xref py py-func docutils literal notranslate"><span class="pre">recvmsg()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/socket.html#socket.socket.recvmsg_into" title="socket.socket.recvmsg_into"><code class="xref py py-func docutils literal notranslate"><span class="pre">recvmsg_into()</span></code></a></p></li>
|
||
</ul>
|
||
<p>(Contributed by David Watson in <a class="reference external" href="https://bugs.python.org/issue6560">bpo-6560</a>, based on an earlier patch by
|
||
Heiko Wundram)</p>
|
||
</li>
|
||
<li><p>The <a class="reference internal" href="../library/socket.html#socket.socket" title="socket.socket"><code class="xref py py-class docutils literal notranslate"><span class="pre">socket</span></code></a> class now supports the PF_CAN protocol family
|
||
(<a class="reference external" href="https://en.wikipedia.org/wiki/Socketcan">https://en.wikipedia.org/wiki/Socketcan</a>), on Linux
|
||
(<a class="reference external" href="https://lwn.net/Articles/253425">https://lwn.net/Articles/253425</a>).</p>
|
||
<p>(Contributed by Matthias Fuchs, updated by Tiago Gonçalves in <a class="reference external" href="https://bugs.python.org/issue10141">bpo-10141</a>.)</p>
|
||
</li>
|
||
<li><p>The <a class="reference internal" href="../library/socket.html#socket.socket" title="socket.socket"><code class="xref py py-class docutils literal notranslate"><span class="pre">socket</span></code></a> class now supports the PF_RDS protocol family
|
||
(<a class="reference external" href="https://en.wikipedia.org/wiki/Reliable_Datagram_Sockets">https://en.wikipedia.org/wiki/Reliable_Datagram_Sockets</a> and
|
||
<a class="reference external" href="https://oss.oracle.com/projects/rds/">https://oss.oracle.com/projects/rds/</a>).</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/socket.html#socket.socket" title="socket.socket"><code class="xref py py-class docutils literal notranslate"><span class="pre">socket</span></code></a> class now supports the <code class="docutils literal notranslate"><span class="pre">PF_SYSTEM</span></code> protocol
|
||
family on OS X. (Contributed by Michael Goderbauer in <a class="reference external" href="https://bugs.python.org/issue13777">bpo-13777</a>.)</p></li>
|
||
<li><p>New function <a class="reference internal" href="../library/socket.html#socket.sethostname" title="socket.sethostname"><code class="xref py py-func docutils literal notranslate"><span class="pre">sethostname()</span></code></a> allows the hostname to be set
|
||
on unix systems if the calling process has sufficient privileges.
|
||
(Contributed by Ross Lagerwall in <a class="reference external" href="https://bugs.python.org/issue10866">bpo-10866</a>.)</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="socketserver">
|
||
<h3>socketserver<a class="headerlink" href="#socketserver" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/socketserver.html#socketserver.BaseServer" title="socketserver.BaseServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseServer</span></code></a> now has an overridable method
|
||
<a class="reference internal" href="../library/socketserver.html#socketserver.BaseServer.service_actions" title="socketserver.BaseServer.service_actions"><code class="xref py py-meth docutils literal notranslate"><span class="pre">service_actions()</span></code></a> that is called by the
|
||
<a class="reference internal" href="../library/socketserver.html#socketserver.BaseServer.serve_forever" title="socketserver.BaseServer.serve_forever"><code class="xref py py-meth docutils literal notranslate"><span class="pre">serve_forever()</span></code></a> method in the service loop.
|
||
<a class="reference internal" href="../library/socketserver.html#socketserver.ForkingMixIn" title="socketserver.ForkingMixIn"><code class="xref py py-class docutils literal notranslate"><span class="pre">ForkingMixIn</span></code></a> now uses this to clean up zombie
|
||
child processes. (Contributed by Justin Warkentin in <a class="reference external" href="https://bugs.python.org/issue11109">bpo-11109</a>.)</p>
|
||
</div>
|
||
<div class="section" id="sqlite3">
|
||
<h3>sqlite3<a class="headerlink" href="#sqlite3" title="Permalink to this headline">¶</a></h3>
|
||
<p>New <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection" title="sqlite3.Connection"><code class="xref py py-class docutils literal notranslate"><span class="pre">sqlite3.Connection</span></code></a> method
|
||
<a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.set_trace_callback" title="sqlite3.Connection.set_trace_callback"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_trace_callback()</span></code></a> can be used to capture a trace of
|
||
all sql commands processed by sqlite. (Contributed by Torsten Landschoff
|
||
in <a class="reference external" href="https://bugs.python.org/issue11688">bpo-11688</a>.)</p>
|
||
</div>
|
||
<div class="section" id="ssl">
|
||
<h3>ssl<a class="headerlink" href="#ssl" title="Permalink to this headline">¶</a></h3>
|
||
<ul>
|
||
<li><p>The <a class="reference internal" href="../library/ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ssl</span></code></a> module has two new random generation functions:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/ssl.html#ssl.RAND_bytes" title="ssl.RAND_bytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">RAND_bytes()</span></code></a>: generate cryptographically strong
|
||
pseudo-random bytes.</p></li>
|
||
<li><p><a class="reference internal" href="../library/ssl.html#ssl.RAND_pseudo_bytes" title="ssl.RAND_pseudo_bytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">RAND_pseudo_bytes()</span></code></a>: generate pseudo-random bytes.</p></li>
|
||
</ul>
|
||
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue12049">bpo-12049</a>.)</p>
|
||
</li>
|
||
<li><p>The <a class="reference internal" href="../library/ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ssl</span></code></a> module now exposes a finer-grained exception hierarchy
|
||
in order to make it easier to inspect the various kinds of errors.
|
||
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue11183">bpo-11183</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/ssl.html#ssl.SSLContext.load_cert_chain" title="ssl.SSLContext.load_cert_chain"><code class="xref py py-meth docutils literal notranslate"><span class="pre">load_cert_chain()</span></code></a> now accepts a <em>password</em> argument
|
||
to be used if the private key is encrypted.
|
||
(Contributed by Adam Simpkins in <a class="reference external" href="https://bugs.python.org/issue12803">bpo-12803</a>.)</p></li>
|
||
<li><p>Diffie-Hellman key exchange, both regular and Elliptic Curve-based, is
|
||
now supported through the <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.load_dh_params" title="ssl.SSLContext.load_dh_params"><code class="xref py py-meth docutils literal notranslate"><span class="pre">load_dh_params()</span></code></a> and
|
||
<a class="reference internal" href="../library/ssl.html#ssl.SSLContext.set_ecdh_curve" title="ssl.SSLContext.set_ecdh_curve"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_ecdh_curve()</span></code></a> methods.
|
||
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue13626">bpo-13626</a> and <a class="reference external" href="https://bugs.python.org/issue13627">bpo-13627</a>.)</p></li>
|
||
<li><p>SSL sockets have a new <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.get_channel_binding" title="ssl.SSLSocket.get_channel_binding"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_channel_binding()</span></code></a> method
|
||
allowing the implementation of certain authentication mechanisms such as
|
||
SCRAM-SHA-1-PLUS. (Contributed by Jacek Konieczny in <a class="reference external" href="https://bugs.python.org/issue12551">bpo-12551</a>.)</p></li>
|
||
<li><p>You can query the SSL compression algorithm used by an SSL socket, thanks
|
||
to its new <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.compression" title="ssl.SSLSocket.compression"><code class="xref py py-meth docutils literal notranslate"><span class="pre">compression()</span></code></a> method. The new attribute
|
||
<a class="reference internal" href="../library/ssl.html#ssl.OP_NO_COMPRESSION" title="ssl.OP_NO_COMPRESSION"><code class="xref py py-attr docutils literal notranslate"><span class="pre">OP_NO_COMPRESSION</span></code></a> can be used to disable compression.
|
||
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue13634">bpo-13634</a>.)</p></li>
|
||
<li><p>Support has been added for the Next Protocol Negotiation extension using
|
||
the <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.set_npn_protocols" title="ssl.SSLContext.set_npn_protocols"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLContext.set_npn_protocols()</span></code></a> method.
|
||
(Contributed by Colin Marc in <a class="reference external" href="https://bugs.python.org/issue14204">bpo-14204</a>.)</p></li>
|
||
<li><p>SSL errors can now be introspected more easily thanks to
|
||
<a class="reference internal" href="../library/ssl.html#ssl.SSLError.library" title="ssl.SSLError.library"><code class="xref py py-attr docutils literal notranslate"><span class="pre">library</span></code></a> and <a class="reference internal" href="../library/ssl.html#ssl.SSLError.reason" title="ssl.SSLError.reason"><code class="xref py py-attr docutils literal notranslate"><span class="pre">reason</span></code></a> attributes.
|
||
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue14837">bpo-14837</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/ssl.html#ssl.get_server_certificate" title="ssl.get_server_certificate"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_server_certificate()</span></code></a> function now supports IPv6.
|
||
(Contributed by Charles-François Natali in <a class="reference external" href="https://bugs.python.org/issue11811">bpo-11811</a>.)</p></li>
|
||
<li><p>New attribute <a class="reference internal" href="../library/ssl.html#ssl.OP_CIPHER_SERVER_PREFERENCE" title="ssl.OP_CIPHER_SERVER_PREFERENCE"><code class="xref py py-attr docutils literal notranslate"><span class="pre">OP_CIPHER_SERVER_PREFERENCE</span></code></a> allows setting
|
||
SSLv3 server sockets to use the server’s cipher ordering preference rather
|
||
than the client’s (<a class="reference external" href="https://bugs.python.org/issue13635">bpo-13635</a>).</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="stat">
|
||
<h3>stat<a class="headerlink" href="#stat" title="Permalink to this headline">¶</a></h3>
|
||
<p>The undocumented tarfile.filemode function has been moved to
|
||
<a class="reference internal" href="../library/stat.html#stat.filemode" title="stat.filemode"><code class="xref py py-func docutils literal notranslate"><span class="pre">stat.filemode()</span></code></a>. It can be used to convert a file’s mode to a string of
|
||
the form ‘-rwxrwxrwx’.</p>
|
||
<p>(Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue14807">bpo-14807</a>.)</p>
|
||
</div>
|
||
<div class="section" id="struct">
|
||
<h3>struct<a class="headerlink" href="#struct" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/struct.html#module-struct" title="struct: Interpret bytes as packed binary data."><code class="xref py py-mod docutils literal notranslate"><span class="pre">struct</span></code></a> module now supports <code class="docutils literal notranslate"><span class="pre">ssize_t</span></code> and <code class="docutils literal notranslate"><span class="pre">size_t</span></code> via the
|
||
new codes <code class="docutils literal notranslate"><span class="pre">n</span></code> and <code class="docutils literal notranslate"><span class="pre">N</span></code>, respectively. (Contributed by Antoine Pitrou
|
||
in <a class="reference external" href="https://bugs.python.org/issue3163">bpo-3163</a>.)</p>
|
||
</div>
|
||
<div class="section" id="subprocess">
|
||
<h3>subprocess<a class="headerlink" href="#subprocess" title="Permalink to this headline">¶</a></h3>
|
||
<p>Command strings can now be bytes objects on posix platforms. (Contributed by
|
||
Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue8513">bpo-8513</a>.)</p>
|
||
<p>A new constant <a class="reference internal" href="../library/subprocess.html#subprocess.DEVNULL" title="subprocess.DEVNULL"><code class="xref py py-data docutils literal notranslate"><span class="pre">DEVNULL</span></code></a> allows suppressing output in a
|
||
platform-independent fashion. (Contributed by Ross Lagerwall in
|
||
<a class="reference external" href="https://bugs.python.org/issue5870">bpo-5870</a>.)</p>
|
||
</div>
|
||
<div class="section" id="sys">
|
||
<h3>sys<a class="headerlink" href="#sys" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> module has a new <a class="reference internal" href="../library/sys.html#sys.thread_info" title="sys.thread_info"><code class="xref py py-data docutils literal notranslate"><span class="pre">thread_info</span></code></a> <a class="reference internal" href="../glossary.html#term-struct-sequence"><span class="xref std std-term">struct
|
||
sequence</span></a> holding information about the thread implementation
|
||
(<a class="reference external" href="https://bugs.python.org/issue11223">bpo-11223</a>).</p>
|
||
</div>
|
||
<div class="section" id="tarfile">
|
||
<h3>tarfile<a class="headerlink" href="#tarfile" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/tarfile.html#module-tarfile" title="tarfile: Read and write tar-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tarfile</span></code></a> now supports <code class="docutils literal notranslate"><span class="pre">lzma</span></code> encoding via the <a class="reference internal" href="../library/lzma.html#module-lzma" title="lzma: A Python wrapper for the liblzma compression library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">lzma</span></code></a> module.
|
||
(Contributed by Lars Gustäbel in <a class="reference external" href="https://bugs.python.org/issue5689">bpo-5689</a>.)</p>
|
||
</div>
|
||
<div class="section" id="tempfile">
|
||
<h3>tempfile<a class="headerlink" href="#tempfile" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/tempfile.html#tempfile.SpooledTemporaryFile" title="tempfile.SpooledTemporaryFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">tempfile.SpooledTemporaryFile</span></code></a>’s
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">truncate()</span></code> method now accepts
|
||
a <code class="docutils literal notranslate"><span class="pre">size</span></code> parameter. (Contributed by Ryan Kelly in <a class="reference external" href="https://bugs.python.org/issue9957">bpo-9957</a>.)</p>
|
||
</div>
|
||
<div class="section" id="textwrap">
|
||
<h3>textwrap<a class="headerlink" href="#textwrap" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/textwrap.html#module-textwrap" title="textwrap: Text wrapping and filling"><code class="xref py py-mod docutils literal notranslate"><span class="pre">textwrap</span></code></a> module has a new <a class="reference internal" href="../library/textwrap.html#textwrap.indent" title="textwrap.indent"><code class="xref py py-func docutils literal notranslate"><span class="pre">indent()</span></code></a> that makes
|
||
it straightforward to add a common prefix to selected lines in a block
|
||
of text (<a class="reference external" href="https://bugs.python.org/issue13857">bpo-13857</a>).</p>
|
||
</div>
|
||
<div class="section" id="threading">
|
||
<h3>threading<a class="headerlink" href="#threading" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/threading.html#threading.Condition" title="threading.Condition"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Condition</span></code></a>, <a class="reference internal" href="../library/threading.html#threading.Semaphore" title="threading.Semaphore"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Semaphore</span></code></a>,
|
||
<a class="reference internal" href="../library/threading.html#threading.BoundedSemaphore" title="threading.BoundedSemaphore"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.BoundedSemaphore</span></code></a>, <a class="reference internal" href="../library/threading.html#threading.Event" title="threading.Event"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Event</span></code></a>, and
|
||
<a class="reference internal" href="../library/threading.html#threading.Timer" title="threading.Timer"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Timer</span></code></a>, all of which used to be factory functions returning a
|
||
class instance, are now classes and may be subclassed. (Contributed by Éric
|
||
Araujo in <a class="reference external" href="https://bugs.python.org/issue10968">bpo-10968</a>.)</p>
|
||
<p>The <a class="reference internal" href="../library/threading.html#threading.Thread" title="threading.Thread"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Thread</span></code></a> constructor now accepts a <code class="docutils literal notranslate"><span class="pre">daemon</span></code> keyword
|
||
argument to override the default behavior of inheriting the <code class="docutils literal notranslate"><span class="pre">daemon</span></code> flag
|
||
value from the parent thread (<a class="reference external" href="https://bugs.python.org/issue6064">bpo-6064</a>).</p>
|
||
<p>The formerly private function <code class="docutils literal notranslate"><span class="pre">_thread.get_ident</span></code> is now available as the
|
||
public function <a class="reference internal" href="../library/threading.html#threading.get_ident" title="threading.get_ident"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.get_ident()</span></code></a>. This eliminates several cases of
|
||
direct access to the <code class="docutils literal notranslate"><span class="pre">_thread</span></code> module in the stdlib. Third party code that
|
||
used <code class="docutils literal notranslate"><span class="pre">_thread.get_ident</span></code> should likewise be changed to use the new public
|
||
interface.</p>
|
||
</div>
|
||
<div class="section" id="time">
|
||
<h3>time<a class="headerlink" href="#time" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <span class="target" id="index-27"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0418"><strong>PEP 418</strong></a> added new functions to the <a class="reference internal" href="../library/time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a> module:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/time.html#time.get_clock_info" title="time.get_clock_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_clock_info()</span></code></a>: Get information on a clock.</p></li>
|
||
<li><p><a class="reference internal" href="../library/time.html#time.monotonic" title="time.monotonic"><code class="xref py py-func docutils literal notranslate"><span class="pre">monotonic()</span></code></a>: Monotonic clock (cannot go backward), not affected
|
||
by system clock updates.</p></li>
|
||
<li><p><a class="reference internal" href="../library/time.html#time.perf_counter" title="time.perf_counter"><code class="xref py py-func docutils literal notranslate"><span class="pre">perf_counter()</span></code></a>: Performance counter with the highest available
|
||
resolution to measure a short duration.</p></li>
|
||
<li><p><a class="reference internal" href="../library/time.html#time.process_time" title="time.process_time"><code class="xref py py-func docutils literal notranslate"><span class="pre">process_time()</span></code></a>: Sum of the system and user CPU time of the
|
||
current process.</p></li>
|
||
</ul>
|
||
<p>Other new functions:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/time.html#time.clock_getres" title="time.clock_getres"><code class="xref py py-func docutils literal notranslate"><span class="pre">clock_getres()</span></code></a>, <a class="reference internal" href="../library/time.html#time.clock_gettime" title="time.clock_gettime"><code class="xref py py-func docutils literal notranslate"><span class="pre">clock_gettime()</span></code></a> and
|
||
<a class="reference internal" href="../library/time.html#time.clock_settime" title="time.clock_settime"><code class="xref py py-func docutils literal notranslate"><span class="pre">clock_settime()</span></code></a> functions with <code class="docutils literal notranslate"><span class="pre">CLOCK_xxx</span></code> constants.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue10278">bpo-10278</a>.)</p></li>
|
||
</ul>
|
||
<p>To improve cross platform consistency, <a class="reference internal" href="../library/time.html#time.sleep" title="time.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">sleep()</span></code></a> now raises a
|
||
<a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> when passed a negative sleep value. Previously this was an
|
||
error on posix, but produced an infinite sleep on Windows.</p>
|
||
</div>
|
||
<div class="section" id="types">
|
||
<h3>types<a class="headerlink" href="#types" title="Permalink to this headline">¶</a></h3>
|
||
<p>Add a new <a class="reference internal" href="../library/types.html#types.MappingProxyType" title="types.MappingProxyType"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.MappingProxyType</span></code></a> class: Read-only proxy of a mapping.
|
||
(<a class="reference external" href="https://bugs.python.org/issue14386">bpo-14386</a>)</p>
|
||
<p>The new functions <a class="reference internal" href="../library/types.html#types.new_class" title="types.new_class"><code class="xref py py-func docutils literal notranslate"><span class="pre">types.new_class()</span></code></a> and <a class="reference internal" href="../library/types.html#types.prepare_class" title="types.prepare_class"><code class="xref py py-func docutils literal notranslate"><span class="pre">types.prepare_class()</span></code></a> provide support
|
||
for PEP 3115 compliant dynamic type creation. (<a class="reference external" href="https://bugs.python.org/issue14588">bpo-14588</a>)</p>
|
||
</div>
|
||
<div class="section" id="unittest">
|
||
<h3>unittest<a class="headerlink" href="#unittest" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertRaises" title="unittest.TestCase.assertRaises"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertRaises()</span></code></a>, <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertRaisesRegex" title="unittest.TestCase.assertRaisesRegex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertRaisesRegex()</span></code></a>, <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertWarns" title="unittest.TestCase.assertWarns"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertWarns()</span></code></a>, and
|
||
<a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertWarnsRegex" title="unittest.TestCase.assertWarnsRegex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertWarnsRegex()</span></code></a> now accept a keyword argument <em>msg</em> when used as
|
||
context managers. (Contributed by Ezio Melotti and Winston Ewert in
|
||
<a class="reference external" href="https://bugs.python.org/issue10775">bpo-10775</a>.)</p>
|
||
<p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.run" title="unittest.TestCase.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestCase.run()</span></code></a> now returns the <a class="reference internal" href="../library/unittest.html#unittest.TestResult" title="unittest.TestResult"><code class="xref py py-class docutils literal notranslate"><span class="pre">TestResult</span></code></a>
|
||
object.</p>
|
||
</div>
|
||
<div class="section" id="urllib">
|
||
<h3>urllib<a class="headerlink" href="#urllib" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request" title="urllib.request.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> class, now accepts a <em>method</em> argument
|
||
used by <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request.get_method" title="urllib.request.Request.get_method"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_method()</span></code></a> to determine what HTTP method
|
||
should be used. For example, this will send a <code class="docutils literal notranslate"><span class="pre">'HEAD'</span></code> request:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">urlopen</span><span class="p">(</span><span class="n">Request</span><span class="p">(</span><span class="s1">'https://www.python.org'</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">'HEAD'</span><span class="p">))</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(<a class="reference external" href="https://bugs.python.org/issue1673007">bpo-1673007</a>)</p>
|
||
</div>
|
||
<div class="section" id="webbrowser">
|
||
<h3>webbrowser<a class="headerlink" href="#webbrowser" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/webbrowser.html#module-webbrowser" title="webbrowser: Easy-to-use controller for Web browsers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">webbrowser</span></code></a> module supports more “browsers”: Google Chrome (named
|
||
<strong class="program">chrome</strong>, <strong class="program">chromium</strong>, <strong class="program">chrome-browser</strong> or
|
||
<strong class="program">chromium-browser</strong> depending on the version and operating system),
|
||
and the generic launchers <strong class="program">xdg-open</strong>, from the FreeDesktop.org
|
||
project, and <strong class="program">gvfs-open</strong>, which is the default URI handler for GNOME
|
||
3. (The former contributed by Arnaud Calmettes in <a class="reference external" href="https://bugs.python.org/issue13620">bpo-13620</a>, the latter
|
||
by Matthias Klose in <a class="reference external" href="https://bugs.python.org/issue14493">bpo-14493</a>.)</p>
|
||
</div>
|
||
<div class="section" id="xml-etree-elementtree">
|
||
<h3>xml.etree.ElementTree<a class="headerlink" href="#xml-etree-elementtree" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/xml.etree.elementtree.html#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.ElementTree</span></code></a> module now imports its C accelerator by
|
||
default; there is no longer a need to explicitly import
|
||
<code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.cElementTree</span></code> (this module stays for backwards compatibility,
|
||
but is now deprecated). In addition, the <code class="docutils literal notranslate"><span class="pre">iter</span></code> family of methods of
|
||
<a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.Element" title="xml.etree.ElementTree.Element"><code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code></a> has been optimized (rewritten in C).
|
||
The module’s documentation has also been greatly improved with added examples
|
||
and a more detailed reference.</p>
|
||
</div>
|
||
<div class="section" id="zlib">
|
||
<h3>zlib<a class="headerlink" href="#zlib" title="Permalink to this headline">¶</a></h3>
|
||
<p>New attribute <a class="reference internal" href="../library/zlib.html#zlib.Decompress.eof" title="zlib.Decompress.eof"><code class="xref py py-attr docutils literal notranslate"><span class="pre">zlib.Decompress.eof</span></code></a> makes it possible to distinguish
|
||
between a properly-formed compressed stream and an incomplete or truncated one.
|
||
(Contributed by Nadeem Vawda in <a class="reference external" href="https://bugs.python.org/issue12646">bpo-12646</a>.)</p>
|
||
<p>New attribute <a class="reference internal" href="../library/zlib.html#zlib.ZLIB_RUNTIME_VERSION" title="zlib.ZLIB_RUNTIME_VERSION"><code class="xref py py-attr docutils literal notranslate"><span class="pre">zlib.ZLIB_RUNTIME_VERSION</span></code></a> reports the version string of
|
||
the underlying <code class="docutils literal notranslate"><span class="pre">zlib</span></code> library that is loaded at runtime. (Contributed by
|
||
Torsten Landschoff in <a class="reference external" href="https://bugs.python.org/issue12306">bpo-12306</a>.)</p>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="optimizations">
|
||
<h2>Optimizations<a class="headerlink" href="#optimizations" title="Permalink to this headline">¶</a></h2>
|
||
<p>Major performance enhancements have been added:</p>
|
||
<ul>
|
||
<li><p>Thanks to <span class="target" id="index-28"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0393"><strong>PEP 393</strong></a>, some operations on Unicode strings have been optimized:</p>
|
||
<ul class="simple">
|
||
<li><p>the memory footprint is divided by 2 to 4 depending on the text</p></li>
|
||
<li><p>encode an ASCII string to UTF-8 doesn’t need to encode characters anymore,
|
||
the UTF-8 representation is shared with the ASCII representation</p></li>
|
||
<li><p>the UTF-8 encoder has been optimized</p></li>
|
||
<li><p>repeating a single ASCII letter and getting a substring of an ASCII string
|
||
is 4 times faster</p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p>UTF-8 is now 2x to 4x faster. UTF-16 encoding is now up to 10x faster.</p>
|
||
<p>(Contributed by Serhiy Storchaka, <a class="reference external" href="https://bugs.python.org/issue14624">bpo-14624</a>, <a class="reference external" href="https://bugs.python.org/issue14738">bpo-14738</a> and
|
||
<a class="reference external" href="https://bugs.python.org/issue15026">bpo-15026</a>.)</p>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="build-and-c-api-changes">
|
||
<h2>Build and C API Changes<a class="headerlink" href="#build-and-c-api-changes" title="Permalink to this headline">¶</a></h2>
|
||
<p>Changes to Python’s build process and to the C API include:</p>
|
||
<ul class="simple">
|
||
<li><p>New <span class="target" id="index-29"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3118"><strong>PEP 3118</strong></a> related function:</p>
|
||
<ul>
|
||
<li><p><a class="reference internal" href="../c-api/memoryview.html#c.PyMemoryView_FromMemory" title="PyMemoryView_FromMemory"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMemoryView_FromMemory()</span></code></a></p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p><span class="target" id="index-30"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0393"><strong>PEP 393</strong></a> added new Unicode types, macros and functions:</p>
|
||
<ul>
|
||
<li><p>High-level API:</p>
|
||
<ul>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_CopyCharacters" title="PyUnicode_CopyCharacters"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_CopyCharacters()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FindChar" title="PyUnicode_FindChar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FindChar()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GetLength" title="PyUnicode_GetLength"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetLength()</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GET_LENGTH" title="PyUnicode_GET_LENGTH"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_GET_LENGTH</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_New" title="PyUnicode_New"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_New()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Substring" title="PyUnicode_Substring"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Substring()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_ReadChar" title="PyUnicode_ReadChar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_ReadChar()</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_WriteChar" title="PyUnicode_WriteChar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_WriteChar()</span></code></a></p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p>Low-level API:</p>
|
||
<ul>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.Py_UCS1" title="Py_UCS1"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UCS1</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.Py_UCS2" title="Py_UCS2"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UCS2</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.Py_UCS4" title="Py_UCS4"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UCS4</span></code></a> types</p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyASCIIObject" title="PyASCIIObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyASCIIObject</span></code></a> and <a class="reference internal" href="../c-api/unicode.html#c.PyCompactUnicodeObject" title="PyCompactUnicodeObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyCompactUnicodeObject</span></code></a> structures</p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_READY" title="PyUnicode_READY"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_READY</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromKindAndData" title="PyUnicode_FromKindAndData"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromKindAndData()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUCS4" title="PyUnicode_AsUCS4"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUCS4()</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUCS4Copy" title="PyUnicode_AsUCS4Copy"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUCS4Copy()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_DATA" title="PyUnicode_DATA"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_DATA</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_1BYTE_DATA" title="PyUnicode_1BYTE_DATA"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_1BYTE_DATA</span></code></a>,
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_2BYTE_DATA" title="PyUnicode_2BYTE_DATA"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_2BYTE_DATA</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_4BYTE_DATA" title="PyUnicode_4BYTE_DATA"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_4BYTE_DATA</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_KIND" title="PyUnicode_KIND"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_KIND</span></code></a> with <code class="xref c c-type docutils literal notranslate"><span class="pre">PyUnicode_Kind</span></code> enum:
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_WCHAR_KIND" title="PyUnicode_WCHAR_KIND"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyUnicode_WCHAR_KIND</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_1BYTE_KIND" title="PyUnicode_1BYTE_KIND"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyUnicode_1BYTE_KIND</span></code></a>,
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_2BYTE_KIND" title="PyUnicode_2BYTE_KIND"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyUnicode_2BYTE_KIND</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_4BYTE_KIND" title="PyUnicode_4BYTE_KIND"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyUnicode_4BYTE_KIND</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_READ" title="PyUnicode_READ"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_READ</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_READ_CHAR" title="PyUnicode_READ_CHAR"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_READ_CHAR</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_WRITE" title="PyUnicode_WRITE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_WRITE</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_MAX_CHAR_VALUE" title="PyUnicode_MAX_CHAR_VALUE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_MAX_CHAR_VALUE</span></code></a></p></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li><p><a class="reference internal" href="../c-api/arg.html#c.PyArg_ParseTuple" title="PyArg_ParseTuple"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyArg_ParseTuple</span></code></a> now accepts a <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> for the <code class="docutils literal notranslate"><span class="pre">c</span></code>
|
||
format (<a class="reference external" href="https://bugs.python.org/issue12380">bpo-12380</a>).</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="deprecated">
|
||
<h2>Deprecated<a class="headerlink" href="#deprecated" title="Permalink to this headline">¶</a></h2>
|
||
<div class="section" id="unsupported-operating-systems">
|
||
<h3>Unsupported Operating Systems<a class="headerlink" href="#unsupported-operating-systems" title="Permalink to this headline">¶</a></h3>
|
||
<p>OS/2 and VMS are no longer supported due to the lack of a maintainer.</p>
|
||
<p>Windows 2000 and Windows platforms which set <code class="docutils literal notranslate"><span class="pre">COMSPEC</span></code> to <code class="docutils literal notranslate"><span class="pre">command.com</span></code>
|
||
are no longer supported due to maintenance burden.</p>
|
||
<p>OSF support, which was deprecated in 3.2, has been completely removed.</p>
|
||
</div>
|
||
<div class="section" id="deprecated-python-modules-functions-and-methods">
|
||
<h3>Deprecated Python modules, functions and methods<a class="headerlink" href="#deprecated-python-modules-functions-and-methods" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Passing a non-empty string to <code class="docutils literal notranslate"><span class="pre">object.__format__()</span></code> is deprecated, and
|
||
will produce a <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> in Python 3.4 (<a class="reference external" href="https://bugs.python.org/issue9856">bpo-9856</a>).</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">unicode_internal</span></code> codec has been deprecated because of the
|
||
<span class="target" id="index-31"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0393"><strong>PEP 393</strong></a>, use UTF-8, UTF-16 (<code class="docutils literal notranslate"><span class="pre">utf-16-le</span></code> or <code class="docutils literal notranslate"><span class="pre">utf-16-be</span></code>), or UTF-32
|
||
(<code class="docutils literal notranslate"><span class="pre">utf-32-le</span></code> or <code class="docutils literal notranslate"><span class="pre">utf-32-be</span></code>)</p></li>
|
||
<li><p><a class="reference internal" href="../library/ftplib.html#ftplib.FTP.nlst" title="ftplib.FTP.nlst"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ftplib.FTP.nlst()</span></code></a> and <a class="reference internal" href="../library/ftplib.html#ftplib.FTP.dir" title="ftplib.FTP.dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ftplib.FTP.dir()</span></code></a>: use
|
||
<a class="reference internal" href="../library/ftplib.html#ftplib.FTP.mlsd" title="ftplib.FTP.mlsd"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ftplib.FTP.mlsd()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/platform.html#platform.popen" title="platform.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">platform.popen()</span></code></a>: use the <a class="reference internal" href="../library/subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> module. Check especially
|
||
the <a class="reference internal" href="../library/subprocess.html#subprocess-replacements"><span class="std std-ref">Replacing Older Functions with the subprocess Module</span></a> section (<a class="reference external" href="https://bugs.python.org/issue11377">bpo-11377</a>).</p></li>
|
||
<li><p><a class="reference external" href="https://bugs.python.org/issue13374">bpo-13374</a>: The Windows bytes API has been deprecated in the <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a>
|
||
module. Use Unicode filenames, instead of bytes filenames, to not depend on
|
||
the ANSI code page anymore and to support any filename.</p></li>
|
||
<li><p><a class="reference external" href="https://bugs.python.org/issue13988">bpo-13988</a>: The <code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.cElementTree</span></code> module is deprecated. The
|
||
accelerator is used automatically whenever available.</p></li>
|
||
<li><p>The behaviour of <a class="reference internal" href="../library/time.html#time.clock" title="time.clock"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.clock()</span></code></a> depends on the platform: use the new
|
||
<a class="reference internal" href="../library/time.html#time.perf_counter" title="time.perf_counter"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.perf_counter()</span></code></a> or <a class="reference internal" href="../library/time.html#time.process_time" title="time.process_time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.process_time()</span></code></a> function instead,
|
||
depending on your requirements, to have a well defined behaviour.</p></li>
|
||
<li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat_float_times()</span></code> function is deprecated.</p></li>
|
||
<li><p><a class="reference internal" href="../library/abc.html#module-abc" title="abc: Abstract base classes according to PEP 3119."><code class="xref py py-mod docutils literal notranslate"><span class="pre">abc</span></code></a> module:</p>
|
||
<ul>
|
||
<li><p><a class="reference internal" href="../library/abc.html#abc.abstractproperty" title="abc.abstractproperty"><code class="xref py py-class docutils literal notranslate"><span class="pre">abc.abstractproperty</span></code></a> has been deprecated, use <a class="reference internal" href="../library/functions.html#property" title="property"><code class="xref py py-class docutils literal notranslate"><span class="pre">property</span></code></a>
|
||
with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.abstractmethod()</span></code></a> instead.</p></li>
|
||
<li><p><a class="reference internal" href="../library/abc.html#abc.abstractclassmethod" title="abc.abstractclassmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">abc.abstractclassmethod</span></code></a> has been deprecated, use
|
||
<a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">classmethod</span></code></a> with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.abstractmethod()</span></code></a> instead.</p></li>
|
||
<li><p><a class="reference internal" href="../library/abc.html#abc.abstractstaticmethod" title="abc.abstractstaticmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">abc.abstractstaticmethod</span></code></a> has been deprecated, use
|
||
<a class="reference internal" href="../library/functions.html#staticmethod" title="staticmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">staticmethod</span></code></a> with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.abstractmethod()</span></code></a> instead.</p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p><a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> package:</p>
|
||
<ul>
|
||
<li><p><a class="reference internal" href="../library/importlib.html#importlib.abc.SourceLoader.path_mtime" title="importlib.abc.SourceLoader.path_mtime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.SourceLoader.path_mtime()</span></code></a> is now deprecated in favour of
|
||
<a class="reference internal" href="../library/importlib.html#importlib.abc.SourceLoader.path_stats" title="importlib.abc.SourceLoader.path_stats"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.SourceLoader.path_stats()</span></code></a> as bytecode files now store
|
||
both the modification time and size of the source file the bytecode file was
|
||
compiled from.</p></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="deprecated-functions-and-types-of-the-c-api">
|
||
<h3>Deprecated functions and types of the C API<a class="headerlink" href="#deprecated-functions-and-types-of-the-c-api" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../c-api/unicode.html#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UNICODE</span></code></a> has been deprecated by <span class="target" id="index-32"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0393"><strong>PEP 393</strong></a> and will be
|
||
removed in Python 4. All functions using this type are deprecated:</p>
|
||
<p>Unicode functions and methods using <a class="reference internal" href="../c-api/unicode.html#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UNICODE</span></code></a> and
|
||
<a class="reference internal" href="../c-api/unicode.html#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UNICODE*</span></code></a> types:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromUnicode" title="PyUnicode_FromUnicode"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_FromUnicode</span></code></a>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromWideChar" title="PyUnicode_FromWideChar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromWideChar()</span></code></a> or
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromKindAndData" title="PyUnicode_FromKindAndData"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromKindAndData()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AS_UNICODE" title="PyUnicode_AS_UNICODE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_AS_UNICODE</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUnicode" title="PyUnicode_AsUnicode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicode()</span></code></a>,
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUnicodeAndSize" title="PyUnicode_AsUnicodeAndSize"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicodeAndSize()</span></code></a>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsWideCharString" title="PyUnicode_AsWideCharString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsWideCharString()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AS_DATA" title="PyUnicode_AS_DATA"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_AS_DATA</span></code></a>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_DATA" title="PyUnicode_DATA"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_DATA</span></code></a> with
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_READ" title="PyUnicode_READ"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_READ</span></code></a> and <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_WRITE" title="PyUnicode_WRITE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_WRITE</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GET_SIZE" title="PyUnicode_GET_SIZE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_GET_SIZE</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GetSize" title="PyUnicode_GetSize"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetSize()</span></code></a>: use
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GET_LENGTH" title="PyUnicode_GET_LENGTH"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_GET_LENGTH</span></code></a> or <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GetLength" title="PyUnicode_GetLength"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetLength()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GET_DATA_SIZE" title="PyUnicode_GET_DATA_SIZE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_GET_DATA_SIZE</span></code></a>: use
|
||
<code class="docutils literal notranslate"><span class="pre">PyUnicode_GET_LENGTH(str)</span> <span class="pre">*</span> <span class="pre">PyUnicode_KIND(str)</span></code> (only work on ready
|
||
strings)</p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUnicodeCopy" title="PyUnicode_AsUnicodeCopy"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicodeCopy()</span></code></a>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUCS4Copy" title="PyUnicode_AsUCS4Copy"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUCS4Copy()</span></code></a> or
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsWideCharString" title="PyUnicode_AsWideCharString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsWideCharString()</span></code></a></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetMax()</span></code></p></li>
|
||
</ul>
|
||
<p>Functions and macros manipulating Py_UNICODE* strings:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strlen</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GetLength" title="PyUnicode_GetLength"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetLength()</span></code></a> or
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GET_LENGTH" title="PyUnicode_GET_LENGTH"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_GET_LENGTH</span></code></a></p></li>
|
||
<li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strcat</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_CopyCharacters" title="PyUnicode_CopyCharacters"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_CopyCharacters()</span></code></a> or
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormat" title="PyUnicode_FromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormat()</span></code></a></p></li>
|
||
<li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strcpy</span></code>, <code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strncpy</span></code>,
|
||
<code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_COPY</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_CopyCharacters" title="PyUnicode_CopyCharacters"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_CopyCharacters()</span></code></a> or
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Substring" title="PyUnicode_Substring"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Substring()</span></code></a></p></li>
|
||
<li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strcmp</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Compare" title="PyUnicode_Compare"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Compare()</span></code></a></p></li>
|
||
<li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strncmp</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Tailmatch" title="PyUnicode_Tailmatch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Tailmatch()</span></code></a></p></li>
|
||
<li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strchr</span></code>, <code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strrchr</span></code>: use
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FindChar" title="PyUnicode_FindChar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FindChar()</span></code></a></p></li>
|
||
<li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_FILL</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Fill" title="PyUnicode_Fill"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Fill()</span></code></a></p></li>
|
||
<li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_MATCH</span></code></p></li>
|
||
</ul>
|
||
<p>Encoders:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Encode" title="PyUnicode_Encode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Encode()</span></code></a>: use <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsEncodedObject()</span></code></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_EncodeUTF7" title="PyUnicode_EncodeUTF7"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF7()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_EncodeUTF8" title="PyUnicode_EncodeUTF8"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF8()</span></code></a>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUTF8" title="PyUnicode_AsUTF8"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUTF8()</span></code></a> or
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUTF8String" title="PyUnicode_AsUTF8String"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUTF8String()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_EncodeUTF32" title="PyUnicode_EncodeUTF32"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF32()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_EncodeUTF16" title="PyUnicode_EncodeUTF16"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF16()</span></code></a></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUnicodeEscape:()</span></code> use
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUnicodeEscapeString" title="PyUnicode_AsUnicodeEscapeString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicodeEscapeString()</span></code></a></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeRawUnicodeEscape:()</span></code> use
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsRawUnicodeEscapeString" title="PyUnicode_AsRawUnicodeEscapeString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsRawUnicodeEscapeString()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_EncodeLatin1" title="PyUnicode_EncodeLatin1"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeLatin1()</span></code></a>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsLatin1String" title="PyUnicode_AsLatin1String"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsLatin1String()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_EncodeASCII" title="PyUnicode_EncodeASCII"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeASCII()</span></code></a>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsASCIIString" title="PyUnicode_AsASCIIString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsASCIIString()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_EncodeCharmap" title="PyUnicode_EncodeCharmap"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeCharmap()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_TranslateCharmap" title="PyUnicode_TranslateCharmap"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_TranslateCharmap()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_EncodeMBCS" title="PyUnicode_EncodeMBCS"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeMBCS()</span></code></a>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsMBCSString" title="PyUnicode_AsMBCSString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsMBCSString()</span></code></a> or
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_EncodeCodePage" title="PyUnicode_EncodeCodePage"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeCodePage()</span></code></a> (with <code class="docutils literal notranslate"><span class="pre">CP_ACP</span></code> code_page)</p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeDecimal()</span></code>,
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_TransformDecimalToASCII" title="PyUnicode_TransformDecimalToASCII"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_TransformDecimalToASCII()</span></code></a></p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="deprecated-features">
|
||
<h3>Deprecated features<a class="headerlink" href="#deprecated-features" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/array.html#module-array" title="array: Space efficient arrays of uniformly typed numeric values."><code class="xref py py-mod docutils literal notranslate"><span class="pre">array</span></code></a> module’s <code class="docutils literal notranslate"><span class="pre">'u'</span></code> format code is now deprecated and will be
|
||
removed in Python 4 together with the rest of the (<a class="reference internal" href="../c-api/unicode.html#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UNICODE</span></code></a>) API.</p>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="porting-to-python-3-3">
|
||
<h2>Porting to Python 3.3<a class="headerlink" href="#porting-to-python-3-3" title="Permalink to this headline">¶</a></h2>
|
||
<p>This section lists previously described changes and other bugfixes
|
||
that may require changes to your code.</p>
|
||
<div class="section" id="porting-python-code">
|
||
<span id="portingpythoncode"></span><h3>Porting Python code<a class="headerlink" href="#porting-python-code" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Hash randomization is enabled by default. Set the <span class="target" id="index-33"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONHASHSEED"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHASHSEED</span></code></a>
|
||
environment variable to <code class="docutils literal notranslate"><span class="pre">0</span></code> to disable hash randomization. See also the
|
||
<a class="reference internal" href="../reference/datamodel.html#object.__hash__" title="object.__hash__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__hash__()</span></code></a> method.</p></li>
|
||
<li><p><a class="reference external" href="https://bugs.python.org/issue12326">bpo-12326</a>: On Linux, sys.platform doesn’t contain the major version
|
||
anymore. It is now always ‘linux’, instead of ‘linux2’ or ‘linux3’ depending
|
||
on the Linux version used to build Python. Replace sys.platform == ‘linux2’
|
||
with sys.platform.startswith(‘linux’), or directly sys.platform == ‘linux’ if
|
||
you don’t need to support older Python versions.</p></li>
|
||
<li><p><a class="reference external" href="https://bugs.python.org/issue13847">bpo-13847</a>, <a class="reference external" href="https://bugs.python.org/issue14180">bpo-14180</a>: <a class="reference internal" href="../library/time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a> and <a class="reference internal" href="../library/datetime.html#module-datetime" title="datetime: Basic date and time types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">datetime</span></code></a>:
|
||
<a class="reference internal" href="../library/exceptions.html#OverflowError" title="OverflowError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OverflowError</span></code></a> is now raised instead of <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> if a
|
||
timestamp is out of range. <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> is now raised if C functions
|
||
<code class="xref c c-func docutils literal notranslate"><span class="pre">gmtime()</span></code> or <code class="xref c c-func docutils literal notranslate"><span class="pre">localtime()</span></code> failed.</p></li>
|
||
<li><p>The default finders used by import now utilize a cache of what is contained
|
||
within a specific directory. If you create a Python source file or sourceless
|
||
bytecode file, make sure to call <a class="reference internal" href="../library/importlib.html#importlib.invalidate_caches" title="importlib.invalidate_caches"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.invalidate_caches()</span></code></a> to clear
|
||
out the cache for the finders to notice the new file.</p></li>
|
||
<li><p><a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> now uses the full name of the module that was attempted to
|
||
be imported. Doctests that check ImportErrors’ message will need to be
|
||
updated to use the full name of the module instead of just the tail of the
|
||
name.</p></li>
|
||
<li><p>The <em>index</em> argument to <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> now defaults to 0 instead of -1
|
||
and no longer support negative values. It was an oversight when <span class="target" id="index-34"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0328"><strong>PEP 328</strong></a> was
|
||
implemented that the default value remained -1. If you need to continue to
|
||
perform a relative import followed by an absolute import, then perform the
|
||
relative import using an index of 1, followed by another import using an
|
||
index of 0. It is preferred, though, that you use
|
||
<a class="reference internal" href="../library/importlib.html#importlib.import_module" title="importlib.import_module"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.import_module()</span></code></a> rather than call <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> directly.</p></li>
|
||
<li><p><a class="reference internal" href="../library/functions.html#__import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> no longer allows one to use an index value other than 0
|
||
for top-level modules. E.g. <code class="docutils literal notranslate"><span class="pre">__import__('sys',</span> <span class="pre">level=1)</span></code> is now an error.</p></li>
|
||
<li><p>Because <a class="reference internal" href="../library/sys.html#sys.meta_path" title="sys.meta_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.meta_path</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.path_hooks" title="sys.path_hooks"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.path_hooks</span></code></a> now have finders on
|
||
them by default, you will most likely want to use <code class="xref py py-meth docutils literal notranslate"><span class="pre">list.insert()</span></code> instead
|
||
of <code class="xref py py-meth docutils literal notranslate"><span class="pre">list.append()</span></code> to add to those lists.</p></li>
|
||
<li><p>Because <code class="docutils literal notranslate"><span class="pre">None</span></code> is now inserted into <a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.path_importer_cache</span></code></a>, if you
|
||
are clearing out entries in the dictionary of paths that do not have a
|
||
finder, you will need to remove keys paired with values of <code class="docutils literal notranslate"><span class="pre">None</span></code> <strong>and</strong>
|
||
<a class="reference internal" href="../library/imp.html#imp.NullImporter" title="imp.NullImporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">imp.NullImporter</span></code></a> to be backwards-compatible. This will lead to extra
|
||
overhead on older versions of Python that re-insert <code class="docutils literal notranslate"><span class="pre">None</span></code> into
|
||
<a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.path_importer_cache</span></code></a> where it represents the use of implicit
|
||
finders, but semantically it should not change anything.</p></li>
|
||
<li><p><a class="reference internal" href="../library/importlib.html#importlib.abc.Finder" title="importlib.abc.Finder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.Finder</span></code></a> no longer specifies a <cite>find_module()</cite> abstract
|
||
method that must be implemented. If you were relying on subclasses to
|
||
implement that method, make sure to check for the method’s existence first.
|
||
You will probably want to check for <cite>find_loader()</cite> first, though, in the
|
||
case of working with <a class="reference internal" href="../glossary.html#term-path-entry-finder"><span class="xref std std-term">path entry finders</span></a>.</p></li>
|
||
<li><p><a class="reference internal" href="../library/pkgutil.html#module-pkgutil" title="pkgutil: Utilities for the import system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pkgutil</span></code></a> has been converted to use <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> internally. This
|
||
eliminates many edge cases where the old behaviour of the PEP 302 import
|
||
emulation failed to match the behaviour of the real import system. The
|
||
import emulation itself is still present, but is now deprecated. The
|
||
<a class="reference internal" href="../library/pkgutil.html#pkgutil.iter_importers" title="pkgutil.iter_importers"><code class="xref py py-func docutils literal notranslate"><span class="pre">pkgutil.iter_importers()</span></code></a> and <a class="reference internal" href="../library/pkgutil.html#pkgutil.walk_packages" title="pkgutil.walk_packages"><code class="xref py py-func docutils literal notranslate"><span class="pre">pkgutil.walk_packages()</span></code></a> functions
|
||
special case the standard import hooks so they are still supported even
|
||
though they do not provide the non-standard <code class="docutils literal notranslate"><span class="pre">iter_modules()</span></code> method.</p></li>
|
||
<li><p>A longstanding RFC-compliance bug (<a class="reference external" href="https://bugs.python.org/issue1079">bpo-1079</a>) in the parsing done by
|
||
<a class="reference internal" href="../library/email.header.html#email.header.decode_header" title="email.header.decode_header"><code class="xref py py-func docutils literal notranslate"><span class="pre">email.header.decode_header()</span></code></a> has been fixed. Code that uses the
|
||
standard idiom to convert encoded headers into unicode
|
||
(<code class="docutils literal notranslate"><span class="pre">str(make_header(decode_header(h))</span></code>) will see no change, but code that
|
||
looks at the individual tuples returned by decode_header will see that
|
||
whitespace that precedes or follows <code class="docutils literal notranslate"><span class="pre">ASCII</span></code> sections is now included in the
|
||
<code class="docutils literal notranslate"><span class="pre">ASCII</span></code> section. Code that builds headers using <code class="docutils literal notranslate"><span class="pre">make_header</span></code> should
|
||
also continue to work without change, since <code class="docutils literal notranslate"><span class="pre">make_header</span></code> continues to add
|
||
whitespace between <code class="docutils literal notranslate"><span class="pre">ASCII</span></code> and non-<code class="docutils literal notranslate"><span class="pre">ASCII</span></code> sections if it is not already
|
||
present in the input strings.</p></li>
|
||
<li><p><a class="reference internal" href="../library/email.utils.html#email.utils.formataddr" title="email.utils.formataddr"><code class="xref py py-func docutils literal notranslate"><span class="pre">email.utils.formataddr()</span></code></a> now does the correct content transfer
|
||
encoding when passed non-<code class="docutils literal notranslate"><span class="pre">ASCII</span></code> display names. Any code that depended on
|
||
the previous buggy behavior that preserved the non-<code class="docutils literal notranslate"><span class="pre">ASCII</span></code> unicode in the
|
||
formatted output string will need to be changed (<a class="reference external" href="https://bugs.python.org/issue1690608">bpo-1690608</a>).</p></li>
|
||
<li><p><a class="reference internal" href="../library/poplib.html#poplib.POP3.quit" title="poplib.POP3.quit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">poplib.POP3.quit()</span></code></a> may now raise protocol errors like all other
|
||
<code class="docutils literal notranslate"><span class="pre">poplib</span></code> methods. Code that assumes <code class="docutils literal notranslate"><span class="pre">quit</span></code> does not raise
|
||
<a class="reference internal" href="../library/poplib.html#poplib.error_proto" title="poplib.error_proto"><code class="xref py py-exc docutils literal notranslate"><span class="pre">poplib.error_proto</span></code></a> errors may need to be changed if errors on <code class="docutils literal notranslate"><span class="pre">quit</span></code>
|
||
are encountered by a particular application (<a class="reference external" href="https://bugs.python.org/issue11291">bpo-11291</a>).</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">strict</span></code> argument to <a class="reference internal" href="../library/email.parser.html#email.parser.Parser" title="email.parser.Parser"><code class="xref py py-class docutils literal notranslate"><span class="pre">email.parser.Parser</span></code></a>, deprecated since
|
||
Python 2.4, has finally been removed.</p></li>
|
||
<li><p>The deprecated method <code class="docutils literal notranslate"><span class="pre">unittest.TestCase.assertSameElements</span></code> has been
|
||
removed.</p></li>
|
||
<li><p>The deprecated variable <code class="docutils literal notranslate"><span class="pre">time.accept2dyear</span></code> has been removed.</p></li>
|
||
<li><p>The deprecated <code class="docutils literal notranslate"><span class="pre">Context._clamp</span></code> attribute has been removed from the
|
||
<a class="reference internal" href="../library/decimal.html#module-decimal" title="decimal: Implementation of the General Decimal Arithmetic Specification."><code class="xref py py-mod docutils literal notranslate"><span class="pre">decimal</span></code></a> module. It was previously replaced by the public attribute
|
||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">clamp</span></code>. (See <a class="reference external" href="https://bugs.python.org/issue8540">bpo-8540</a>.)</p></li>
|
||
<li><p>The undocumented internal helper class <code class="docutils literal notranslate"><span class="pre">SSLFakeFile</span></code> has been removed
|
||
from <a class="reference internal" href="../library/smtplib.html#module-smtplib" title="smtplib: SMTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtplib</span></code></a>, since its functionality has long been provided directly
|
||
by <a class="reference internal" href="../library/socket.html#socket.socket.makefile" title="socket.socket.makefile"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.socket.makefile()</span></code></a>.</p></li>
|
||
<li><p>Passing a negative value to <a class="reference internal" href="../library/time.html#time.sleep" title="time.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.sleep()</span></code></a> on Windows now raises an
|
||
error instead of sleeping forever. It has always raised an error on posix.</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">ast.__version__</span></code> constant has been removed. If you need to
|
||
make decisions affected by the AST version, use <a class="reference internal" href="../library/sys.html#sys.version_info" title="sys.version_info"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.version_info</span></code></a>
|
||
to make the decision.</p></li>
|
||
<li><p>Code that used to work around the fact that the <a class="reference internal" href="../library/threading.html#module-threading" title="threading: Thread-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code></a> module used
|
||
factory functions by subclassing the private classes will need to change to
|
||
subclass the now-public classes.</p></li>
|
||
<li><p>The undocumented debugging machinery in the threading module has been
|
||
removed, simplifying the code. This should have no effect on production
|
||
code, but is mentioned here in case any application debug frameworks were
|
||
interacting with it (<a class="reference external" href="https://bugs.python.org/issue13550">bpo-13550</a>).</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="porting-c-code">
|
||
<h3>Porting C code<a class="headerlink" href="#porting-c-code" title="Permalink to this headline">¶</a></h3>
|
||
<ul>
|
||
<li><p>In the course of changes to the buffer API the undocumented
|
||
<code class="xref c c-member docutils literal notranslate"><span class="pre">smalltable</span></code> member of the
|
||
<a class="reference internal" href="../c-api/buffer.html#c.Py_buffer" title="Py_buffer"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_buffer</span></code></a> structure has been removed and the
|
||
layout of the <code class="xref c c-type docutils literal notranslate"><span class="pre">PyMemoryViewObject</span></code> has changed.</p>
|
||
<p>All extensions relying on the relevant parts in <code class="docutils literal notranslate"><span class="pre">memoryobject.h</span></code>
|
||
or <code class="docutils literal notranslate"><span class="pre">object.h</span></code> must be rebuilt.</p>
|
||
</li>
|
||
<li><p>Due to <a class="reference internal" href="#pep-393"><span class="std std-ref">PEP 393</span></a>, the <a class="reference internal" href="../c-api/unicode.html#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UNICODE</span></code></a> type and all
|
||
functions using this type are deprecated (but will stay available for
|
||
at least five years). If you were using low-level Unicode APIs to
|
||
construct and access unicode objects and you want to benefit of the
|
||
memory footprint reduction provided by PEP 393, you have to convert
|
||
your code to the new <a class="reference internal" href="../c-api/unicode.html"><span class="doc">Unicode API</span></a>.</p>
|
||
<p>However, if you only have been using high-level functions such as
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Concat" title="PyUnicode_Concat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Concat()</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Join" title="PyUnicode_Join"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Join()</span></code></a> or
|
||
<a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormat" title="PyUnicode_FromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormat()</span></code></a>, your code will automatically take
|
||
advantage of the new unicode representations.</p>
|
||
</li>
|
||
<li><p><a class="reference internal" href="../c-api/import.html#c.PyImport_GetMagicNumber" title="PyImport_GetMagicNumber"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_GetMagicNumber()</span></code></a> now returns <code class="docutils literal notranslate"><span class="pre">-1</span></code> upon failure.</p></li>
|
||
<li><p>As a negative value for the <em>level</em> argument to <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> is no
|
||
longer valid, the same now holds for <a class="reference internal" href="../c-api/import.html#c.PyImport_ImportModuleLevel" title="PyImport_ImportModuleLevel"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModuleLevel()</span></code></a>.
|
||
This also means that the value of <em>level</em> used by
|
||
<a class="reference internal" href="../c-api/import.html#c.PyImport_ImportModuleEx" title="PyImport_ImportModuleEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModuleEx()</span></code></a> is now <code class="docutils literal notranslate"><span class="pre">0</span></code> instead of <code class="docutils literal notranslate"><span class="pre">-1</span></code>.</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="building-c-extensions">
|
||
<h3>Building C extensions<a class="headerlink" href="#building-c-extensions" title="Permalink to this headline">¶</a></h3>
|
||
<ul>
|
||
<li><p>The range of possible file names for C extensions has been narrowed.
|
||
Very rarely used spellings have been suppressed: under POSIX, files
|
||
named <code class="docutils literal notranslate"><span class="pre">xxxmodule.so</span></code>, <code class="docutils literal notranslate"><span class="pre">xxxmodule.abi3.so</span></code> and
|
||
<code class="docutils literal notranslate"><span class="pre">xxxmodule.cpython-*.so</span></code> are no longer recognized as implementing
|
||
the <code class="docutils literal notranslate"><span class="pre">xxx</span></code> module. If you had been generating such files, you have
|
||
to switch to the other spellings (i.e., remove the <code class="docutils literal notranslate"><span class="pre">module</span></code> string
|
||
from the file names).</p>
|
||
<p>(implemented in <a class="reference external" href="https://bugs.python.org/issue14040">bpo-14040</a>.)</p>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="command-line-switch-changes">
|
||
<h3>Command Line Switch Changes<a class="headerlink" href="#command-line-switch-changes" title="Permalink to this headline">¶</a></h3>
|
||
<ul>
|
||
<li><p>The -Q command-line flag and related artifacts have been removed. Code
|
||
checking sys.flags.division_warning will need updating.</p>
|
||
<p>(<a class="reference external" href="https://bugs.python.org/issue10998">bpo-10998</a>, contributed by Éric Araujo.)</p>
|
||
</li>
|
||
<li><p>When <strong class="program">python</strong> is started with <a class="reference internal" href="../using/cmdline.html#id3"><code class="xref std std-option docutils literal notranslate"><span class="pre">-S</span></code></a>, <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">site</span></code>
|
||
will no longer add site-specific paths to the module search paths. In
|
||
previous versions, it did.</p>
|
||
<p>(<a class="reference external" href="https://bugs.python.org/issue11591">bpo-11591</a>, contributed by Carl Meyer with editions by Éric Araujo.)</p>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper">
|
||
<h3><a href="../contents.html">Table of Contents</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">What’s New In Python 3.3</a><ul>
|
||
<li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
|
||
<li><a class="reference internal" href="#pep-405-virtual-environments">PEP 405: Virtual Environments</a></li>
|
||
<li><a class="reference internal" href="#pep-420-implicit-namespace-packages">PEP 420: Implicit Namespace Packages</a></li>
|
||
<li><a class="reference internal" href="#pep-3118-new-memoryview-implementation-and-buffer-protocol-documentation">PEP 3118: New memoryview implementation and buffer protocol documentation</a><ul>
|
||
<li><a class="reference internal" href="#features">Features</a></li>
|
||
<li><a class="reference internal" href="#api-changes">API changes</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#pep-393-flexible-string-representation">PEP 393: Flexible String Representation</a><ul>
|
||
<li><a class="reference internal" href="#functionality">Functionality</a></li>
|
||
<li><a class="reference internal" href="#performance-and-resource-usage">Performance and resource usage</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#pep-397-python-launcher-for-windows">PEP 397: Python Launcher for Windows</a></li>
|
||
<li><a class="reference internal" href="#pep-3151-reworking-the-os-and-io-exception-hierarchy">PEP 3151: Reworking the OS and IO exception hierarchy</a></li>
|
||
<li><a class="reference internal" href="#pep-380-syntax-for-delegating-to-a-subgenerator">PEP 380: Syntax for Delegating to a Subgenerator</a></li>
|
||
<li><a class="reference internal" href="#pep-409-suppressing-exception-context">PEP 409: Suppressing exception context</a></li>
|
||
<li><a class="reference internal" href="#pep-414-explicit-unicode-literals">PEP 414: Explicit Unicode literals</a></li>
|
||
<li><a class="reference internal" href="#pep-3155-qualified-name-for-classes-and-functions">PEP 3155: Qualified name for classes and functions</a></li>
|
||
<li><a class="reference internal" href="#pep-412-key-sharing-dictionary">PEP 412: Key-Sharing Dictionary</a></li>
|
||
<li><a class="reference internal" href="#pep-362-function-signature-object">PEP 362: Function Signature Object</a></li>
|
||
<li><a class="reference internal" href="#pep-421-adding-sys-implementation">PEP 421: Adding sys.implementation</a><ul>
|
||
<li><a class="reference internal" href="#simplenamespace">SimpleNamespace</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#using-importlib-as-the-implementation-of-import">Using importlib as the Implementation of Import</a><ul>
|
||
<li><a class="reference internal" href="#new-apis">New APIs</a></li>
|
||
<li><a class="reference internal" href="#visible-changes">Visible Changes</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
|
||
<li><a class="reference internal" href="#a-finer-grained-import-lock">A Finer-Grained Import Lock</a></li>
|
||
<li><a class="reference internal" href="#builtin-functions-and-types">Builtin functions and types</a></li>
|
||
<li><a class="reference internal" href="#new-modules">New Modules</a><ul>
|
||
<li><a class="reference internal" href="#faulthandler">faulthandler</a></li>
|
||
<li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
|
||
<li><a class="reference internal" href="#lzma">lzma</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
|
||
<li><a class="reference internal" href="#abc">abc</a></li>
|
||
<li><a class="reference internal" href="#array">array</a></li>
|
||
<li><a class="reference internal" href="#base64">base64</a></li>
|
||
<li><a class="reference internal" href="#binascii">binascii</a></li>
|
||
<li><a class="reference internal" href="#bz2">bz2</a></li>
|
||
<li><a class="reference internal" href="#codecs">codecs</a></li>
|
||
<li><a class="reference internal" href="#collections">collections</a></li>
|
||
<li><a class="reference internal" href="#contextlib">contextlib</a></li>
|
||
<li><a class="reference internal" href="#crypt">crypt</a></li>
|
||
<li><a class="reference internal" href="#curses">curses</a></li>
|
||
<li><a class="reference internal" href="#datetime">datetime</a></li>
|
||
<li><a class="reference internal" href="#decimal">decimal</a><ul>
|
||
<li><a class="reference internal" href="#id1">Features</a></li>
|
||
<li><a class="reference internal" href="#id2">API changes</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#email">email</a><ul>
|
||
<li><a class="reference internal" href="#policy-framework">Policy Framework</a></li>
|
||
<li><a class="reference internal" href="#provisional-policy-with-new-header-api">Provisional Policy with New Header API</a></li>
|
||
<li><a class="reference internal" href="#other-api-changes">Other API Changes</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#ftplib">ftplib</a></li>
|
||
<li><a class="reference internal" href="#functools">functools</a></li>
|
||
<li><a class="reference internal" href="#gc">gc</a></li>
|
||
<li><a class="reference internal" href="#hmac">hmac</a></li>
|
||
<li><a class="reference internal" href="#http">http</a></li>
|
||
<li><a class="reference internal" href="#html">html</a></li>
|
||
<li><a class="reference internal" href="#imaplib">imaplib</a></li>
|
||
<li><a class="reference internal" href="#inspect">inspect</a></li>
|
||
<li><a class="reference internal" href="#io">io</a></li>
|
||
<li><a class="reference internal" href="#itertools">itertools</a></li>
|
||
<li><a class="reference internal" href="#logging">logging</a></li>
|
||
<li><a class="reference internal" href="#math">math</a></li>
|
||
<li><a class="reference internal" href="#mmap">mmap</a></li>
|
||
<li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
|
||
<li><a class="reference internal" href="#nntplib">nntplib</a></li>
|
||
<li><a class="reference internal" href="#os">os</a></li>
|
||
<li><a class="reference internal" href="#pdb">pdb</a></li>
|
||
<li><a class="reference internal" href="#pickle">pickle</a></li>
|
||
<li><a class="reference internal" href="#pydoc">pydoc</a></li>
|
||
<li><a class="reference internal" href="#re">re</a></li>
|
||
<li><a class="reference internal" href="#sched">sched</a></li>
|
||
<li><a class="reference internal" href="#select">select</a></li>
|
||
<li><a class="reference internal" href="#shlex">shlex</a></li>
|
||
<li><a class="reference internal" href="#shutil">shutil</a></li>
|
||
<li><a class="reference internal" href="#signal">signal</a></li>
|
||
<li><a class="reference internal" href="#smtpd">smtpd</a></li>
|
||
<li><a class="reference internal" href="#smtplib">smtplib</a></li>
|
||
<li><a class="reference internal" href="#socket">socket</a></li>
|
||
<li><a class="reference internal" href="#socketserver">socketserver</a></li>
|
||
<li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
|
||
<li><a class="reference internal" href="#ssl">ssl</a></li>
|
||
<li><a class="reference internal" href="#stat">stat</a></li>
|
||
<li><a class="reference internal" href="#struct">struct</a></li>
|
||
<li><a class="reference internal" href="#subprocess">subprocess</a></li>
|
||
<li><a class="reference internal" href="#sys">sys</a></li>
|
||
<li><a class="reference internal" href="#tarfile">tarfile</a></li>
|
||
<li><a class="reference internal" href="#tempfile">tempfile</a></li>
|
||
<li><a class="reference internal" href="#textwrap">textwrap</a></li>
|
||
<li><a class="reference internal" href="#threading">threading</a></li>
|
||
<li><a class="reference internal" href="#time">time</a></li>
|
||
<li><a class="reference internal" href="#types">types</a></li>
|
||
<li><a class="reference internal" href="#unittest">unittest</a></li>
|
||
<li><a class="reference internal" href="#urllib">urllib</a></li>
|
||
<li><a class="reference internal" href="#webbrowser">webbrowser</a></li>
|
||
<li><a class="reference internal" href="#xml-etree-elementtree">xml.etree.ElementTree</a></li>
|
||
<li><a class="reference internal" href="#zlib">zlib</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#optimizations">Optimizations</a></li>
|
||
<li><a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a></li>
|
||
<li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
|
||
<li><a class="reference internal" href="#unsupported-operating-systems">Unsupported Operating Systems</a></li>
|
||
<li><a class="reference internal" href="#deprecated-python-modules-functions-and-methods">Deprecated Python modules, functions and methods</a></li>
|
||
<li><a class="reference internal" href="#deprecated-functions-and-types-of-the-c-api">Deprecated functions and types of the C API</a></li>
|
||
<li><a class="reference internal" href="#deprecated-features">Deprecated features</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#porting-to-python-3-3">Porting to Python 3.3</a><ul>
|
||
<li><a class="reference internal" href="#porting-python-code">Porting Python code</a></li>
|
||
<li><a class="reference internal" href="#porting-c-code">Porting C code</a></li>
|
||
<li><a class="reference internal" href="#building-c-extensions">Building C extensions</a></li>
|
||
<li><a class="reference internal" href="#command-line-switch-changes">Command Line Switch Changes</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="3.4.html"
|
||
title="previous chapter">What’s New In Python 3.4</a></p>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="3.2.html"
|
||
title="next chapter">What’s New In Python 3.2</a></p>
|
||
<div role="note" aria-label="source link">
|
||
<h3>This Page</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="../bugs.html">Report a Bug</a></li>
|
||
<li>
|
||
<a href="https://github.com/python/cpython/blob/3.7/Doc/whatsnew/3.3.rst"
|
||
rel="nofollow">Show Source
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
>index</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="right" >
|
||
<a href="3.2.html" title="What’s New In Python 3.2"
|
||
>next</a> |</li>
|
||
<li class="right" >
|
||
<a href="3.4.html" title="What’s New In Python 3.4"
|
||
>previous</a> |</li>
|
||
<li><img src="../_static/py.png" alt=""
|
||
style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li>
|
||
<span class="language_switcher_placeholder">en</span>
|
||
<span class="version_switcher_placeholder">3.7.4</span>
|
||
<a href="../index.html">Documentation </a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> »</li>
|
||
<li class="right">
|
||
|
||
|
||
<div class="inline-search" style="display: none" role="search">
|
||
<form class="inline-search" action="../search.html" method="get">
|
||
<input placeholder="Quick search" type="text" name="q" />
|
||
<input type="submit" value="Go" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
<script type="text/javascript">$('.inline-search').show(0);</script>
|
||
|
|
||
</li>
|
||
|
||
</ul>
|
||
</div>
|
||
<div class="footer">
|
||
© <a href="../copyright.html">Copyright</a> 2001-2019, Python Software Foundation.
|
||
<br />
|
||
The Python Software Foundation is a non-profit corporation.
|
||
<a href="https://www.python.org/psf/donations/">Please donate.</a>
|
||
<br />
|
||
Last updated on Jul 13, 2019.
|
||
<a href="../bugs.html">Found a bug</a>?
|
||
<br />
|
||
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.0.1.
|
||
</div>
|
||
|
||
</body>
|
||
</html> |