Sophie

Sophie

distrib > Mageia > 3 > i586 > media > core-updates > by-pkgid > 50402eac2a16508b365658612a898528 > files > 935

python3-docs-3.3.0-4.3.mga3.noarch.rpm



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>What’s New In Python 3.3 &mdash; Python v3.3.0 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">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.3.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </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/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python v3.3.0 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python v3.3.0 documentation" href="../index.html" />
    <link rel="up" title="What’s New in Python" href="index.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" href="index.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
 

  </head>
  <body>
    <div class="related">
      <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="index.html" title="What’s New in Python"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="http://www.python.org/">Python</a> &raquo;</li>
        <li><a href="../index.html">3.3.0 Documentation</a> &raquo;</li>

          <li><a href="index.html" accesskey="U">What&#8217;s New in Python</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="what-s-new-in-python-3-3">
<h1>What&#8217;s New In Python 3.3<a class="headerlink" href="#what-s-new-in-python-3-3" title="Permalink to this headline">¶</a></h1>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Author:</th><td class="field-body">Raymond Hettinger</td>
</tr>
<tr class="field"><th class="field-name">Release:</th><td class="field-body">3.3.0</td>
</tr>
<tr class="field"><th class="field-name">Date:</th><td class="field-body">September 29, 2012</td>
</tr>
</tbody>
</table>
<p>This article explains the new features in Python 3.3, compared to 3.2.
Python 3.3 was released on September 29, 2012.</p>
<div class="section" id="summary-release-highlights">
<h2>Summary &#8211; 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>New <tt class="docutils literal"><span class="pre">yield</span> <span class="pre">from</span></tt> expression for <a class="reference internal" href="#pep-380"><em>generator delegation</em></a>.</li>
<li>The <tt class="docutils literal"><span class="pre">u'unicode'</span></tt> syntax is accepted again for <a class="reference internal" href="../library/functions.html#str" title="str"><tt class="xref py py-class docutils literal"><span class="pre">str</span></tt></a> objects.</li>
</ul>
<p>New library modules:</p>
<ul class="simple">
<li><a class="reference internal" href="../library/faulthandler.html#module-faulthandler" title="faulthandler: Dump the Python traceback."><tt class="xref py py-mod docutils literal"><span class="pre">faulthandler</span></tt></a> (helps debugging low-level crashes)</li>
<li><a class="reference internal" href="../library/ipaddress.html#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><tt class="xref py py-mod docutils literal"><span class="pre">ipaddress</span></tt></a> (high-level objects representing IP addresses and masks)</li>
<li><a class="reference internal" href="../library/lzma.html#module-lzma" title="lzma: A Python wrapper for the liblzma compression library."><tt class="xref py py-mod docutils literal"><span class="pre">lzma</span></tt></a> (compress data using the XZ / LZMA algorithm)</li>
<li><a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><tt class="xref py py-mod docutils literal"><span class="pre">venv</span></tt></a> (Python <a class="reference internal" href="#pep-405"><em>virtual environments</em></a>, as in the
popular <tt class="docutils literal"><span class="pre">virtualenv</span></tt> package)</li>
</ul>
<p>New built-in features:</p>
<ul class="simple">
<li>Reworked <a class="reference internal" href="#pep-3151"><em>I/O exception hierarchy</em></a>.</li>
</ul>
<p>Implementation improvements:</p>
<ul class="simple">
<li>Rewritten <a class="reference internal" href="#importlib"><em>import machinery</em></a> based on <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: An implementation of the import machinery."><tt class="xref py py-mod docutils literal"><span class="pre">importlib</span></tt></a>.</li>
<li>More compact <a class="reference internal" href="#pep-393"><em>unicode strings</em></a>.</li>
<li>More compact <a class="reference internal" href="#pep-412"><em>attribute dictionaries</em></a>.</li>
</ul>
<p>Security improvements:</p>
<ul class="simple">
<li>Hash randomization is switched on by default.</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>
<dl class="docutils">
<dt><span class="target" id="index-0"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-0405"><strong>PEP 405</strong></a> - Python Virtual Environments</dt>
<dd>PEP written by Carl Meyer, implemented by Carl Meyer and Vinay Sajip.</dd>
</dl>
<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
<tt class="docutils literal"><span class="pre">virtualenv</span></tt> 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."><tt class="xref py py-mod docutils literal"><span class="pre">venv</span></tt></a> module for programmatic access, and the
<a class="reference internal" href="../using/scripts.html#scripts-pyvenv"><em>pyvenv</em></a> script for command-line access and
administration.  The Python interpreter becomes aware of a <tt class="docutils literal"><span class="pre">pvenv.cfg</span></tt>
file whose existence signals the base of a virtual environment&#8217;s directory
tree.</p>
</div>
<div class="section" id="pep-420-namespace-packages">
<h2>PEP 420: Namespace Packages<a class="headerlink" href="#pep-420-namespace-packages" title="Permalink to this headline">¶</a></h2>
<p>Native support for package directories that don&#8217;t require <tt class="docutils literal"><span class="pre">__init__.py</span></tt>
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-1"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-0420"><strong>PEP 420</strong></a>)</p>
</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>
<dl class="docutils">
<dt><a class="reference external" href="http://bugs.python.org/issue10181">issue 10181</a> - memoryview bug fixes and features.</dt>
<dd>Written by Stefan Krah.</dd>
</dl>
<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&#8217;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>All native single character format specifiers in struct module syntax
(optionally prefixed with &#8216;&#64;&#8217;) are now supported.</li>
<li>With some restrictions, the cast() method allows changing of format and
shape of C-contiguous arrays.</li>
<li>Multi-dimensional list representations are supported for any array type.</li>
<li>Multi-dimensional comparisons are supported for any array type.</li>
<li>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="http://bugs.python.org/issue13411">issue 13411</a>)</li>
<li>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.</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>The maximum number of dimensions is officially limited to 64.</li>
<li>The representation of empty shape, strides and suboffsets is now
an empty tuple instead of None.</li>
<li>Accessing a memoryview element with format &#8216;B&#8217; (unsigned bytes)
now returns an integer (in accordance with the struct module syntax).
For returning a bytes object the view must be cast to &#8216;c&#8217; first.</li>
<li>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.</li>
<li>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> .</li>
</ul>
</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-2"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-0393"><strong>PEP 393</strong></a> are the following:</p>
<ul class="simple">
<li>Python now always supports the full range of Unicode codepoints, including
non-BMP ones (i.e. from <tt class="docutils literal"><span class="pre">U+0000</span></tt> to <tt class="docutils literal"><span class="pre">U+10FFFF</span></tt>).  The distinction between
narrow and wide builds no longer exists and Python now behaves like a wide
build, even under Windows.</li>
<li>With the death of narrow builds, the problems specific to narrow builds have
also been fixed, for example:<ul>
<li><a class="reference internal" href="../library/functions.html#len" title="len"><tt class="xref py py-func docutils literal"><span class="pre">len()</span></tt></a> now always returns 1 for non-BMP characters,
so <tt class="docutils literal"><span class="pre">len('\U0010FFFF')</span> <span class="pre">==</span> <span class="pre">1</span></tt>;</li>
<li>surrogate pairs are not recombined in string literals,
so <tt class="docutils literal"><span class="pre">'\uDBFF\uDFFF'</span> <span class="pre">!=</span> <span class="pre">'\U0010FFFF'</span></tt>;</li>
<li>indexing or slicing non-BMP characters returns the expected value,
so <tt class="docutils literal"><span class="pre">'\U0010FFFF'[0]</span></tt> now returns <tt class="docutils literal"><span class="pre">'\U0010FFFF'</span></tt> and not <tt class="docutils literal"><span class="pre">'\uDBFF'</span></tt>;</li>
<li>all other functions in the standard library now correctly handle
non-BMP codepoints.</li>
</ul>
</li>
<li>The value of <a class="reference internal" href="../library/sys.html#sys.maxunicode" title="sys.maxunicode"><tt class="xref py py-data docutils literal"><span class="pre">sys.maxunicode</span></tt></a> is now always <tt class="docutils literal"><span class="pre">1114111</span></tt> (<tt class="docutils literal"><span class="pre">0x10FFFF</span></tt>
in hexadecimal).  The <tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_GetMax()</span></tt> function still returns
either <tt class="docutils literal"><span class="pre">0xFFFF</span></tt> or <tt class="docutils literal"><span class="pre">0x10FFFF</span></tt> for backward compatibility, and it should
not be used with the new Unicode API (see <a class="reference external" href="http://bugs.python.org/issue13054">issue 13054</a>).</li>
<li>The <tt class="file docutils literal"><span class="pre">./configure</span></tt> flag <tt class="docutils literal"><span class="pre">--with-wide-unicode</span></tt> has been removed.</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 codepoint in the string:</p>
<ul class="simple">
<li>pure ASCII and Latin1 strings (<tt class="docutils literal"><span class="pre">U+0000-U+00FF</span></tt>) use 1 byte per codepoint;</li>
<li>BMP strings (<tt class="docutils literal"><span class="pre">U+0000-U+FFFF</span></tt>) use 2 bytes per codepoint;</li>
<li>non-BMP strings (<tt class="docutils literal"><span class="pre">U+10000-U+10FFFF</span></tt>) use 4 bytes per codepoint.</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>
</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>
<dl class="docutils">
<dt><span class="target" id="index-3"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-3151"><strong>PEP 3151</strong></a> - Reworking the OS and IO exception hierarchy</dt>
<dd>PEP written and implemented by Antoine Pitrou.</dd>
</dl>
<p>The hierarchy of exceptions raised by operating system errors is now both
simplified and finer-grained.</p>
<p>You don&#8217;t have to worry anymore about choosing the appropriate exception
type between <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a>, <a class="reference internal" href="../library/exceptions.html#IOError" title="IOError"><tt class="xref py py-exc docutils literal"><span class="pre">IOError</span></tt></a>, <a class="reference internal" href="../library/exceptions.html#EnvironmentError" title="EnvironmentError"><tt class="xref py py-exc docutils literal"><span class="pre">EnvironmentError</span></tt></a>,
<a class="reference internal" href="../library/exceptions.html#WindowsError" title="WindowsError"><tt class="xref py py-exc docutils literal"><span class="pre">WindowsError</span></tt></a>, <tt class="xref py py-exc docutils literal"><span class="pre">mmap.error</span></tt>, <a class="reference internal" href="../library/socket.html#socket.error" title="socket.error"><tt class="xref py py-exc docutils literal"><span class="pre">socket.error</span></tt></a> or
<a class="reference internal" href="../library/select.html#select.error" title="select.error"><tt class="xref py py-exc docutils literal"><span class="pre">select.error</span></tt></a>.  All these exception types are now only one:
<a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></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 <tt class="docutils literal"><span class="pre">errno</span></tt> attribute (or <tt class="docutils literal"><span class="pre">args[0]</span></tt>) for a particular
constant from the <a class="reference internal" href="../library/errno.html#module-errno" title="errno: Standard errno system symbols."><tt class="xref py py-mod docutils literal"><span class="pre">errno</span></tt></a> module, you can catch the adequate
<a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> subclass.  The available subclasses are the following:</p>
<ul class="simple">
<li><a class="reference internal" href="../library/exceptions.html#BlockingIOError" title="BlockingIOError"><tt class="xref py py-exc docutils literal"><span class="pre">BlockingIOError</span></tt></a></li>
<li><a class="reference internal" href="../library/exceptions.html#ChildProcessError" title="ChildProcessError"><tt class="xref py py-exc docutils literal"><span class="pre">ChildProcessError</span></tt></a></li>
<li><a class="reference internal" href="../library/exceptions.html#ConnectionError" title="ConnectionError"><tt class="xref py py-exc docutils literal"><span class="pre">ConnectionError</span></tt></a></li>
<li><a class="reference internal" href="../library/exceptions.html#FileExistsError" title="FileExistsError"><tt class="xref py py-exc docutils literal"><span class="pre">FileExistsError</span></tt></a></li>
<li><a class="reference internal" href="../library/exceptions.html#FileNotFoundError" title="FileNotFoundError"><tt class="xref py py-exc docutils literal"><span class="pre">FileNotFoundError</span></tt></a></li>
<li><a class="reference internal" href="../library/exceptions.html#InterruptedError" title="InterruptedError"><tt class="xref py py-exc docutils literal"><span class="pre">InterruptedError</span></tt></a></li>
<li><a class="reference internal" href="../library/exceptions.html#IsADirectoryError" title="IsADirectoryError"><tt class="xref py py-exc docutils literal"><span class="pre">IsADirectoryError</span></tt></a></li>
<li><a class="reference internal" href="../library/exceptions.html#NotADirectoryError" title="NotADirectoryError"><tt class="xref py py-exc docutils literal"><span class="pre">NotADirectoryError</span></tt></a></li>
<li><a class="reference internal" href="../library/exceptions.html#PermissionError" title="PermissionError"><tt class="xref py py-exc docutils literal"><span class="pre">PermissionError</span></tt></a></li>
<li><a class="reference internal" href="../library/exceptions.html#ProcessLookupError" title="ProcessLookupError"><tt class="xref py py-exc docutils literal"><span class="pre">ProcessLookupError</span></tt></a></li>
<li><a class="reference internal" href="../library/exceptions.html#TimeoutError" title="TimeoutError"><tt class="xref py py-exc docutils literal"><span class="pre">TimeoutError</span></tt></a></li>
</ul>
<p>And the <a class="reference internal" href="../library/exceptions.html#ConnectionError" title="ConnectionError"><tt class="xref py py-exc docutils literal"><span class="pre">ConnectionError</span></tt></a> itself has finer-grained subclasses:</p>
<ul class="simple">
<li><tt class="xref py py-exc docutils literal"><span class="pre">BrokenPipeError</span></tt></li>
<li><a class="reference internal" href="../library/exceptions.html#ConnectionAbortedError" title="ConnectionAbortedError"><tt class="xref py py-exc docutils literal"><span class="pre">ConnectionAbortedError</span></tt></a></li>
<li><a class="reference internal" href="../library/exceptions.html#ConnectionRefusedError" title="ConnectionRefusedError"><tt class="xref py py-exc docutils literal"><span class="pre">ConnectionRefusedError</span></tt></a></li>
<li><a class="reference internal" href="../library/exceptions.html#ConnectionResetError" title="ConnectionResetError"><tt class="xref py py-exc docutils literal"><span class="pre">ConnectionResetError</span></tt></a></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."><tt class="xref py py-mod docutils literal"><span class="pre">errno</span></tt></a> can now be
avoided.  For example, the following code written for Python 3.2:</p>
<div class="highlight-python3"><div class="highlight"><pre><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="s">&quot;document.txt&quot;</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="s">&quot;document.txt file is missing&quot;</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="s">&quot;You are not allowed to read document.txt&quot;</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."><tt class="xref py py-mod docutils literal"><span class="pre">errno</span></tt></a> import and without manual
inspection of exception attributes:</p>
<div class="highlight-python3"><div class="highlight"><pre><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="s">&quot;document.txt&quot;</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="n">FileNotFoundError</span><span class="p">:</span>
    <span class="nb">print</span><span class="p">(</span><span class="s">&quot;document.txt file is missing&quot;</span><span class="p">)</span>
<span class="k">except</span> <span class="n">PermissionError</span><span class="p">:</span>
    <span class="nb">print</span><span class="p">(</span><span class="s">&quot;You are not allowed to read document.txt&quot;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="pep-380-syntax-for-delegating-to-a-subgenerator">
<span id="pep-380"></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>
<dl class="docutils">
<dt><span class="target" id="index-4"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-0380"><strong>PEP 380</strong></a> - Syntax for Delegating to a Subgenerator</dt>
<dd>PEP written by Greg Ewing.</dd>
</dl>
<p>PEP 380 adds the <tt class="docutils literal"><span class="pre">yield</span> <span class="pre">from</span></tt> expression, allowing a generator to delegate
part of its operations to another generator. This allows a section of code
containing &#8216;yield&#8217; 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 <tt class="docutils literal"><span class="pre">yield</span>
<span class="pre">from</span></tt> expression actually allows delegation to arbitrary subiterators.</p>
<p>For simple iterators, <tt class="docutils literal"><span class="pre">yield</span> <span class="pre">from</span> <span class="pre">iterable</span></tt> is essentially just a shortened
form of <tt class="docutils literal"><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></tt>:</p>
<div class="highlight-python3"><pre>&gt;&gt;&gt; def g(x):
...     yield from range(x, 0, -1)
...     yield from range(x)
...
&gt;&gt;&gt; list(g(5))
[5, 4, 3, 2, 1, 0, 1, 2, 3, 4]</pre>
</div>
<p>However, unlike an ordinary loop, <tt class="docutils literal"><span class="pre">yield</span> <span class="pre">from</span></tt> 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"><pre>&gt;&gt;&gt; def accumulate(start=0):
...     tally = start
...     while 1:
...         next = yield
...         if next is None:
...             return tally
...         tally += next
...
&gt;&gt;&gt; def gather_tallies(tallies, start=0):
...     while 1:
...         tally = yield from accumulate()
...         tallies.append(tally)
...
&gt;&gt;&gt; tallies = []
&gt;&gt;&gt; acc = gather_tallies(tallies)
&gt;&gt;&gt; next(acc) # Ensure the accumulator is ready to accept values
&gt;&gt;&gt; for i in range(10):
...     acc.send(i)
...
&gt;&gt;&gt; acc.send(None) # Finish the first tally
&gt;&gt;&gt; for i in range(5):
...     acc.send(i)
...
&gt;&gt;&gt; acc.send(None) # Finish the second tally
&gt;&gt;&gt; tallies
[45, 10]</pre>
</div>
<p>The main principle driving this change is to allow even generators that are
designed to be used with the <tt class="docutils literal"><span class="pre">send</span></tt> and <tt class="docutils literal"><span class="pre">throw</span></tt> methods to be split into
multiple subgenerators as easily as a single large function can be split into
multiple subfunctions.</p>
<p>(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>
</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>
<dl class="docutils">
<dt><span class="target" id="index-5"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-0409"><strong>PEP 409</strong></a> - Suppressing exception context</dt>
<dd>PEP written by Ethan Furman, implemented by Ethan Furman and Nick Coghlan.</dd>
</dl>
<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"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </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">&gt;&gt;&gt; </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">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n-Identifier">&lt;module&gt;</span>
  File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">8</span>, in <span class="n-Identifier">__getattr__</span>
<span class="nc">AttributeError</span>: <span class="n-Identifier">x</span>
</pre></div>
</div>
<p>Without the <tt class="docutils literal"><span class="pre">from</span> <span class="pre">None</span></tt> suffix to suppress the cause, the original
exception would be displayed by default:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </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">&gt;&gt;&gt; </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">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">6</span>, in <span class="n-Identifier">__getattr__</span>
<span class="nc">KeyError</span>: <span class="n-Identifier">&#39;x&#39;</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">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n-Identifier">&lt;module&gt;</span>
  File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">8</span>, in <span class="n-Identifier">__getattr__</span>
<span class="nc">AttributeError</span>: <span class="n-Identifier">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"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </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(&#39;x&#39;,)</span>
</pre></div>
</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>
<dl class="docutils">
<dt><span class="target" id="index-6"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-0414"><strong>PEP 414</strong></a> - Explicit Unicode literals</dt>
<dd>PEP written by Armin Ronacher.</dd>
</dl>
<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
&#8220;<tt class="docutils literal"><span class="pre">u</span></tt>&#8221; 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>
<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>
<dl class="docutils">
<dt><span class="target" id="index-7"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-3155"><strong>PEP 3155</strong></a> - Qualified name for classes and functions</dt>
<dd>PEP written and implemented by Antoine Pitrou.</dd>
</dl>
<p>Functions and class objects have a new <tt class="docutils literal"><span class="pre">__qualname__</span></tt> attribute representing
the &#8220;path&#8221; from the module top-level to their definition.  For global functions
and classes, this is the same as <tt class="docutils literal"><span class="pre">__name__</span></tt>.  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"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </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">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">meth</span><span class="o">.</span><span class="n">__name__</span>
<span class="go">&#39;meth&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">meth</span><span class="o">.</span><span class="n">__qualname__</span>
<span class="go">&#39;C.meth&#39;</span>
</pre></div>
</div>
<p>Example with nested classes:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </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">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">D</span><span class="o">.</span><span class="n">__name__</span>
<span class="go">&#39;D&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">D</span><span class="o">.</span><span class="n">__qualname__</span>
<span class="go">&#39;C.D&#39;</span>
<span class="gp">&gt;&gt;&gt; </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="n">__name__</span>
<span class="go">&#39;meth&#39;</span>
<span class="gp">&gt;&gt;&gt; </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="n">__qualname__</span>
<span class="go">&#39;C.D.meth&#39;</span>
</pre></div>
</div>
<p>Example with nested functions:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </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">&gt;&gt;&gt; </span><span class="n">outer</span><span class="p">()</span><span class="o">.</span><span class="n">__name__</span>
<span class="go">&#39;inner&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">outer</span><span class="p">()</span><span class="o">.</span><span class="n">__qualname__</span>
<span class="go">&#39;outer.&lt;locals&gt;.inner&#39;</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"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </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">&quot;&lt;class &#39;__main__.C.D&#39;&gt;&quot;</span>
<span class="gp">&gt;&gt;&gt; </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">&#39;&lt;function C.D.meth at 0x7f46b9fe31e0&gt;&#39;</span>
</pre></div>
</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>
<dl class="docutils">
<dt><span class="target" id="index-8"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-0412"><strong>PEP 412</strong></a> - Key-Sharing Dictionary</dt>
<dd>PEP written and implemented by Mark Shannon.</dd>
</dl>
<p>Dictionaries used for the storage of objects&#8217; 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>
<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>
<dl class="docutils">
<dt><span class="target" id="index-9"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-0362"><strong>PEP 362</strong></a>: -  Function Signature Object</dt>
<dd>PEP written by Brett Cannon, Yury Selivanov, Larry Hastings, Jiwon Seo.
Implemented by Yury Selivanov.</dd>
</dl>
<p>A new function <a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><tt class="xref py py-func docutils literal"><span class="pre">inspect.signature()</span></tt></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"><tt class="xref py py-func docutils literal"><span class="pre">functools.partial()</span></tt></a>
objects.  New classes <a class="reference internal" href="../library/inspect.html#inspect.Signature" title="inspect.Signature"><tt class="xref py py-class docutils literal"><span class="pre">inspect.Signature</span></tt></a>, <a class="reference internal" href="../library/inspect.html#inspect.Parameter" title="inspect.Parameter"><tt class="xref py py-class docutils literal"><span class="pre">inspect.Parameter</span></tt></a>
and <a class="reference internal" href="../library/inspect.html#inspect.BoundArguments" title="inspect.BoundArguments"><tt class="xref py py-class docutils literal"><span class="pre">inspect.BoundArguments</span></tt></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>
<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="http://bugs.python.org/issue2377">issue 2377</a> - Replace __import__ w/ importlib.__import__
<a class="reference external" href="http://bugs.python.org/issue13959">issue 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."><tt class="xref py py-mod docutils literal"><span class="pre">imp</span></tt></a> in pure Python
<a class="reference external" href="http://bugs.python.org/issue14605">issue 14605</a> - Make import machinery explicit
<a class="reference external" href="http://bugs.python.org/issue14646">issue 14646</a> - Require loaders set __loader__ and __package__</p>
<p>(Written by Brett Cannon)</p>
<p>The <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><tt class="xref py py-func docutils literal"><span class="pre">__import__()</span></tt></a> function is now powered by <a class="reference internal" href="../library/importlib.html#importlib.__import__" title="importlib.__import__"><tt class="xref py py-func docutils literal"><span class="pre">importlib.__import__()</span></tt></a>.
This work leads to the completion of &#8220;phase 2&#8221; of <span class="target" id="index-10"></span><a class="pep reference external" href="http://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, this change should result in no visible change in
semantics. Any possible changes required in one&#8217;s code to handle this change
should read the <a class="reference internal" href="#porting-python-code">Porting Python code</a> section of this document to see what
needs to be changed, but it will only affect those that currently manipulate
import or try calling it programmatically.</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: An implementation of the import machinery."><tt class="xref py py-mod docutils literal"><span class="pre">importlib</span></tt></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"><tt class="xref py py-mod docutils literal"><span class="pre">importlib.abc</span></tt></a> have been expanded
to properly delineate between <a class="reference internal" href="../glossary.html#term-meta-path-finder"><em class="xref std std-term">meta path finders</em></a>
and <a class="reference internal" href="../glossary.html#term-path-entry-finder"><em class="xref std std-term">path entry finders</em></a> by introducing
<a class="reference internal" href="../library/importlib.html#importlib.abc.MetaPathFinder" title="importlib.abc.MetaPathFinder"><tt class="xref py py-class docutils literal"><span class="pre">importlib.abc.MetaPathFinder</span></tt></a> and
<a class="reference internal" href="../library/importlib.html#importlib.abc.PathEntryFinder" title="importlib.abc.PathEntryFinder"><tt class="xref py py-class docutils literal"><span class="pre">importlib.abc.PathEntryFinder</span></tt></a>, respectively. The old ABC of
<a class="reference internal" href="../library/importlib.html#importlib.abc.Finder" title="importlib.abc.Finder"><tt class="xref py py-class docutils literal"><span class="pre">importlib.abc.Finder</span></tt></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"><tt class="xref py py-class docutils literal"><span class="pre">importlib.machinery.FileFinder</span></tt></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"><tt class="xref py py-attr docutils literal"><span class="pre">sys.path_hooks</span></tt></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"><tt class="xref py py-class docutils literal"><span class="pre">importlib.abc.FileLoader</span></tt></a> helps
write a loader that uses the file system as the storage mechanism for a module&#8217;s
code. The loader for source files
(<a class="reference internal" href="../library/importlib.html#importlib.machinery.SourceFileLoader" title="importlib.machinery.SourceFileLoader"><tt class="xref py py-class docutils literal"><span class="pre">importlib.machinery.SourceFileLoader</span></tt></a>), sourceless bytecode files
(<a class="reference internal" href="../library/importlib.html#importlib.machinery.SourcelessFileLoader" title="importlib.machinery.SourcelessFileLoader"><tt class="xref py py-class docutils literal"><span class="pre">importlib.machinery.SourcelessFileLoader</span></tt></a>), and extension modules
(<a class="reference internal" href="../library/importlib.html#importlib.machinery.ExtensionFileLoader" title="importlib.machinery.ExtensionFileLoader"><tt class="xref py py-class docutils literal"><span class="pre">importlib.machinery.ExtensionFileLoader</span></tt></a>) are now available for
direct use.</p>
<p><a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><tt class="xref py py-exc docutils literal"><span class="pre">ImportError</span></tt></a> now has <tt class="docutils literal"><span class="pre">name</span></tt> and <tt class="docutils literal"><span class="pre">path</span></tt> 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&#8217;s name.</p>
<p>The <a class="reference internal" href="../library/importlib.html#importlib.invalidate_caches" title="importlib.invalidate_caches"><tt class="xref py py-func docutils literal"><span class="pre">importlib.invalidate_caches()</span></tt></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"><tt class="xref py py-attr docutils literal"><span class="pre">sys.path_importer_cache</span></tt></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: An implementation of the import machinery."><tt class="xref py py-mod docutils literal"><span class="pre">importlib</span></tt></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"><tt class="xref py py-attr docutils literal"><span class="pre">sys.meta_path</span></tt></a> and
<a class="reference internal" href="../library/sys.html#sys.path_hooks" title="sys.path_hooks"><tt class="xref py py-attr docutils literal"><span class="pre">sys.path_hooks</span></tt></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&#8217;s needs.</p>
<p>Another change is that all modules have a <tt class="docutils literal"><span class="pre">__loader__</span></tt> attribute, storing the
loader used to create the module. <span class="target" id="index-11"></span><a class="pep reference external" href="http://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 <tt class="docutils literal"><span class="pre">__package__</span></tt> attribute from
<span class="target" id="index-12"></span><a class="pep reference external" href="http://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: An implementation of the import machinery."><tt class="xref py py-mod docutils literal"><span class="pre">importlib</span></tt></a> and import itself is setting the attribute post-load.</p>
<p><tt class="xref docutils literal"><span class="pre">None</span></tt> is now inserted into <a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><tt class="xref py py-attr docutils literal"><span class="pre">sys.path_importer_cache</span></tt></a> when no finder
can be found on <a class="reference internal" href="../library/sys.html#sys.path_hooks" title="sys.path_hooks"><tt class="xref py py-attr docutils literal"><span class="pre">sys.path_hooks</span></tt></a>. Since <a class="reference internal" href="../library/imp.html#imp.NullImporter" title="imp.NullImporter"><tt class="xref py py-class docutils literal"><span class="pre">imp.NullImporter</span></tt></a> is not
directly exposed on <a class="reference internal" href="../library/sys.html#sys.path_hooks" title="sys.path_hooks"><tt class="xref py py-attr docutils literal"><span class="pre">sys.path_hooks</span></tt></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>
</div>
</div>
<div class="section" id="new-email-package-features">
<h2>New Email Package Features<a class="headerlink" href="#new-email-package-features" title="Permalink to this headline">¶</a></h2>
<div class="section" id="policy-framework">
<h3>Policy Framework<a class="headerlink" href="#policy-framework" title="Permalink to this headline">¶</a></h3>
<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"><tt class="xref py py-mod docutils literal"><span class="pre">policy</span></tt></a> framework.  A
<a class="reference internal" href="../library/email.policy.html#email.policy.Policy" title="email.policy.Policy"><tt class="xref py py-class docutils literal"><span class="pre">Policy</span></tt></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"><tt class="xref py py-class docutils literal"><span class="pre">Compat32</span></tt></a> policy, which provides backward
compatibility with the email package in Python 3.2.  A <tt class="docutils literal"><span class="pre">policy</span></tt> 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."><tt class="xref py py-mod docutils literal"><span class="pre">parser</span></tt></a>, or when a
<a class="reference internal" href="../library/email.message.html#email.message.Message" title="email.message.Message"><tt class="xref py py-class docutils literal"><span class="pre">Message</span></tt></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."><tt class="xref py py-mod docutils literal"><span class="pre">generator</span></tt></a>.  Unless overridden, a policy passed
to a <tt class="docutils literal"><span class="pre">parser</span></tt> is inherited by all the <tt class="docutils literal"><span class="pre">Message</span></tt> object and sub-objects
created by the <tt class="docutils literal"><span class="pre">parser</span></tt>.  By default a <tt class="docutils literal"><span class="pre">generator</span></tt> will use the policy of
the <tt class="docutils literal"><span class="pre">Message</span></tt> object it is serializing.  The default policy is
<tt class="xref py py-data docutils literal"><span class="pre">compat32</span></tt>.</p>
<p>The minimum set of controls implemented by all <tt class="docutils literal"><span class="pre">policy</span></tt> objects are:</p>
<blockquote>
<div><table border="1" class="docutils">
<colgroup>
<col width="21%" />
<col width="79%" />
</colgroup>
<tbody valign="top">
<tr><td>max_line_length</td>
<td>The maximum length, excluding the linesep character(s),
individual lines may have when a <tt class="docutils literal"><span class="pre">Message</span></tt> is
serialized.  Defaults to 78.</td>
</tr>
<tr><td>linesep</td>
<td>The character used to separate individual lines when a
<tt class="docutils literal"><span class="pre">Message</span></tt> is serialized.  Defaults to <tt class="docutils literal"><span class="pre">\n</span></tt>.</td>
</tr>
<tr><td>cte_type</td>
<td><tt class="docutils literal"><span class="pre">7bit</span></tt> or <tt class="docutils literal"><span class="pre">8bit</span></tt>.  <tt class="docutils literal"><span class="pre">8bit</span></tt> applies only to a
<tt class="docutils literal"><span class="pre">Bytes</span></tt> <tt class="docutils literal"><span class="pre">generator</span></tt>, and means that non-ASCII may
be used where allowed by the protocol (or where it
exists in the original input).</td>
</tr>
<tr><td>raise_on_defect</td>
<td>Causes a <tt class="docutils literal"><span class="pre">parser</span></tt> to raise error when defects are
encountered instead of adding them to the <tt class="docutils literal"><span class="pre">Message</span></tt>
object&#8217;s <tt class="docutils literal"><span class="pre">defects</span></tt> list.</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"><tt class="xref py py-meth docutils literal"><span class="pre">clone()</span></tt></a> method of policy objects.  <tt class="docutils literal"><span class="pre">clone</span></tt> 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
<tt class="docutils literal"><span class="pre">\r\n</span></tt> linesep characters like this:</p>
<div class="highlight-python3"><div class="highlight"><pre><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="s">&#39;</span><span class="se">\r\n</span><span class="s">&#39;</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
<tt class="docutils literal"><span class="pre">linesep='\r\n'</span></tt> in all the places you call a <tt class="docutils literal"><span class="pre">generator</span></tt>, you can specify
it once, when you set the policy used by the <tt class="docutils literal"><span class="pre">parser</span></tt> or the <tt class="docutils literal"><span class="pre">Message</span></tt>,
whichever your program uses to create <tt class="docutils literal"><span class="pre">Message</span></tt> objects.  On the other hand,
if you need to generate messages in multiple forms, you can still specify the
parameters in the appropriate <tt class="docutils literal"><span class="pre">generator</span></tt> call.  Or you can have custom
policy instances for your different cases, and pass those in when you create
the <tt class="docutils literal"><span class="pre">generator</span></tt>.</p>
</div>
<div class="section" id="provisional-policy-with-new-header-api">
<h3>Provisional Policy with New Header API<a class="headerlink" href="#provisional-policy-with-new-header-api" title="Permalink to this headline">¶</a></h3>
<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"><em class="xref std std-term">provisional policy</em></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"><tt class="xref py py-class docutils literal"><span class="pre">EmailPolicy</span></tt></a>,
and add the following additional controls:</p>
<blockquote>
<div><table border="1" class="docutils">
<colgroup>
<col width="21%" />
<col width="79%" />
</colgroup>
<tbody valign="top">
<tr><td>refold_source</td>
<td>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."><tt class="xref py py-mod docutils literal"><span class="pre">parser</span></tt></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."><tt class="xref py py-mod docutils literal"><span class="pre">generator</span></tt></a>.  It can be <tt class="docutils literal"><span class="pre">none</span></tt>, <tt class="docutils literal"><span class="pre">long</span></tt>,
or <tt class="docutils literal"><span class="pre">all</span></tt>.  The default is <tt class="docutils literal"><span class="pre">long</span></tt>, which means that
source headers with a line longer than
<tt class="docutils literal"><span class="pre">max_line_length</span></tt> get refolded.  <tt class="docutils literal"><span class="pre">none</span></tt> means no
line get refolded, and <tt class="docutils literal"><span class="pre">all</span></tt> means that all lines
get refolded.</td>
</tr>
<tr><td>header_factory</td>
<td>A callable that take a <tt class="docutils literal"><span class="pre">name</span></tt> and <tt class="docutils literal"><span class="pre">value</span></tt> and
produces a custom header object.</td>
</tr>
</tbody>
</table>
</div></blockquote>
<p>The <tt class="docutils literal"><span class="pre">header_factory</span></tt> 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 <tt class="docutils literal"><span class="pre">Message</span></tt> object is an object produced by the <tt class="docutils literal"><span class="pre">header_factory</span></tt>, and any
time you set a header on a <tt class="docutils literal"><span class="pre">Message</span></tt> it becomes an object produced by
<tt class="docutils literal"><span class="pre">header_factory</span></tt>.  All such header objects have a <tt class="docutils literal"><span class="pre">name</span></tt> 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"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </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">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s">&#39;To&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;Éric &lt;foo@example.com&gt;&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s">&#39;to&#39;</span><span class="p">]</span>
<span class="go">&#39;Éric &lt;foo@example.com&gt;&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s">&#39;to&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">addresses</span>
<span class="go">(Address(display_name=&#39;Éric&#39;, username=&#39;foo&#39;, domain=&#39;example.com&#39;),)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s">&#39;to&#39;</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">&#39;foo&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s">&#39;to&#39;</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">&#39;Éric&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s">&#39;Date&#39;</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">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s">&#39;Date&#39;</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), &#39;EDT&#39;))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s">&#39;Date&#39;</span><span class="p">]</span>
<span class="go">&#39;Fri, 25 May 2012 21:44:27 -0400&#39;</span>
<span class="gp">&gt;&gt;&gt; </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?= &lt;foo@example.com&gt;</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
<tt class="docutils literal"><span class="pre">utf-8</span></tt> 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"><tt class="xref py py-mod docutils literal"><span class="pre">email.header</span></tt></a> <a class="reference internal" href="../library/email.header.html#email.header.decode_header" title="email.header.decode_header"><tt class="xref py py-meth docutils literal"><span class="pre">decode_header()</span></tt></a> or
<a class="reference internal" href="../library/email.header.html#email.header.make_header" title="email.header.make_header"><tt class="xref py py-meth docutils literal"><span class="pre">make_header()</span></tt></a> functions.</p>
<p>You can also create addresses from parts:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s">&#39;cc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">Group</span><span class="p">(</span><span class="s">&#39;pals&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Address</span><span class="p">(</span><span class="s">&#39;Bob&#39;</span><span class="p">,</span> <span class="s">&#39;bob&#39;</span><span class="p">,</span> <span class="s">&#39;example.com&#39;</span><span class="p">),</span>
<span class="gp">... </span>                          <span class="n">Address</span><span class="p">(</span><span class="s">&#39;Sally&#39;</span><span class="p">,</span> <span class="s">&#39;sally&#39;</span><span class="p">,</span> <span class="s">&#39;example.com&#39;</span><span class="p">)]),</span>
<span class="gp">... </span>           <span class="n">Address</span><span class="p">(</span><span class="s">&#39;Bonzo&#39;</span><span class="p">,</span> <span class="n">addr_spec</span><span class="o">=</span><span class="s">&#39;bonz@laugh.com&#39;</span><span class="p">)]</span>
<span class="gp">&gt;&gt;&gt; </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?= &lt;foo@example.com&gt;</span>
<span class="go">Date: Fri, 25 May 2012 21:44:27 -0400</span>
<span class="go">cc: pals: Bob &lt;bob@example.com&gt;, Sally &lt;sally@example.com&gt;;, Bonzo &lt;bonz@laugh.com&gt;</span>
</pre></div>
</div>
<p>Decoding to unicode is done automatically:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </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">&gt;&gt;&gt; </span><span class="n">m2</span><span class="p">[</span><span class="s">&#39;to&#39;</span><span class="p">]</span>
<span class="go">&#39;Éric &lt;foo@example.com&gt;&#39;</span>
</pre></div>
</div>
<p>When you parse a message, you can use the <tt class="docutils literal"><span class="pre">addresses</span></tt> and <tt class="docutils literal"><span class="pre">groups</span></tt>
attributes of the header objects to access the groups and individual
addresses:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">m2</span><span class="p">[</span><span class="s">&#39;cc&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">addresses</span>
<span class="go">(Address(display_name=&#39;Bob&#39;, username=&#39;bob&#39;, domain=&#39;example.com&#39;), Address(display_name=&#39;Sally&#39;, username=&#39;sally&#39;, domain=&#39;example.com&#39;), Address(display_name=&#39;Bonzo&#39;, username=&#39;bonz&#39;, domain=&#39;laugh.com&#39;))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m2</span><span class="p">[</span><span class="s">&#39;cc&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">groups</span>
<span class="go">(Group(display_name=&#39;pals&#39;, addresses=(Address(display_name=&#39;Bob&#39;, username=&#39;bob&#39;, domain=&#39;example.com&#39;), Address(display_name=&#39;Sally&#39;, username=&#39;sally&#39;, domain=&#39;example.com&#39;)), Group(display_name=None, addresses=(Address(display_name=&#39;Bonzo&#39;, username=&#39;bonz&#39;, domain=&#39;laugh.com&#39;),))</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>
<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 class="first">Added support for Unicode name aliases and named sequences.
Both <a class="reference internal" href="../library/unicodedata.html#unicodedata.lookup" title="unicodedata.lookup"><tt class="xref py py-func docutils literal"><span class="pre">unicodedata.lookup()</span></tt></a> and <tt class="docutils literal"><span class="pre">'\N{...}'</span></tt> now resolve name aliases,
and <a class="reference internal" href="../library/unicodedata.html#unicodedata.lookup" title="unicodedata.lookup"><tt class="xref py py-func docutils literal"><span class="pre">unicodedata.lookup()</span></tt></a> resolves named sequences too.</p>
<p>(Contributed by Ezio Melotti in <a class="reference external" href="http://bugs.python.org/issue12753">issue 12753</a>)</p>
</li>
<li><p class="first">Equality comparisons on <a class="reference internal" href="../library/stdtypes.html#range" title="range"><tt class="xref py py-func docutils literal"><span class="pre">range()</span></tt></a> objects now return a result reflecting
the equality of the underlying sequences generated by those range objects.</p>
<p>(<a class="reference external" href="http://bugs.python.org/issue13201">issue 13201</a>)</p>
</li>
<li><p class="first">The <tt class="docutils literal"><span class="pre">count()</span></tt>, <tt class="docutils literal"><span class="pre">find()</span></tt>, <tt class="docutils literal"><span class="pre">rfind()</span></tt>, <tt class="docutils literal"><span class="pre">index()</span></tt> and <tt class="docutils literal"><span class="pre">rindex()</span></tt>
methods of <a class="reference internal" href="../library/functions.html#bytes" title="bytes"><tt class="xref py py-class docutils literal"><span class="pre">bytes</span></tt></a> and <a class="reference internal" href="../library/functions.html#bytearray" title="bytearray"><tt class="xref py py-class docutils literal"><span class="pre">bytearray</span></tt></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="http://bugs.python.org/issue12170">issue 12170</a>)</p>
</li>
<li><p class="first">New methods have been added to <a class="reference internal" href="../library/stdtypes.html#list" title="list"><tt class="xref py py-class docutils literal"><span class="pre">list</span></tt></a> and <a class="reference internal" href="../library/functions.html#bytearray" title="bytearray"><tt class="xref py py-class docutils literal"><span class="pre">bytearray</span></tt></a>:
<tt class="docutils literal"><span class="pre">copy()</span></tt> and <tt class="docutils literal"><span class="pre">clear()</span></tt>.</p>
<p>(<a class="reference external" href="http://bugs.python.org/issue10516">issue 10516</a>)</p>
</li>
<li><p class="first">Raw bytes literals can now be written <tt class="docutils literal"><span class="pre">rb&quot;...&quot;</span></tt> as well as <tt class="docutils literal"><span class="pre">br&quot;...&quot;</span></tt>.
(Contributed by Antoine Pitrou in <a class="reference external" href="http://bugs.python.org/issue13748">issue 13748</a>.)</p>
</li>
<li><p class="first"><a class="reference internal" href="../library/stdtypes.html#dict.setdefault" title="dict.setdefault"><tt class="xref py py-meth docutils literal"><span class="pre">dict.setdefault()</span></tt></a> now does only one lookup for the given key, making
it atomic when used with built-in types.
(Contributed by Filip Gruszczyński in <a class="reference external" href="http://bugs.python.org/issue13521">issue 13521</a>.)</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#PyImport_ImportModuleNoBlock" title="PyImport_ImportModuleNoBlock"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModuleNoBlock()</span></tt></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="http://bugs.python.org/issue9260">issue 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><a class="reference internal" href="../library/functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></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"><tt class="xref py py-data docutils literal"><span class="pre">os.O_CLOEXEC</span></tt></a> for
example. The <tt class="docutils literal"><span class="pre">'x'</span></tt> mode was added: open for exclusive creation, failing if
the file already exists.</li>
<li><a class="reference internal" href="../library/functions.html#print" title="print"><tt class="xref py py-func docutils literal"><span class="pre">print()</span></tt></a>: added the <em>flush</em> keyword argument. If the <em>flush</em> keyword
argument is true, the stream is forcibly flushed.</li>
<li><a class="reference internal" href="../library/functions.html#hash" title="hash"><tt class="xref py py-func docutils literal"><span class="pre">hash()</span></tt></a>: hash randomization is enabled by default, see
<a class="reference internal" href="../reference/datamodel.html#object.__hash__" title="object.__hash__"><tt class="xref py py-meth docutils literal"><span class="pre">object.__hash__()</span></tt></a> and <span class="target" id="index-13"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONHASHSEED"><tt class="xref std std-envvar docutils literal"><span class="pre">PYTHONHASHSEED</span></tt></a>.</li>
<li>The <a class="reference internal" href="../library/functions.html#str" title="str"><tt class="xref py py-class docutils literal"><span class="pre">str</span></tt></a> type gets a new <a class="reference internal" href="../library/stdtypes.html#str.casefold" title="str.casefold"><tt class="xref py py-meth docutils literal"><span class="pre">casefold()</span></tt></a> method: return a
casefolded copy of the string, casefolded strings may be used for caseless
matching. For example, <tt class="docutils literal"><span class="pre">'ß'.casefold()</span></tt> returns <tt class="docutils literal"><span class="pre">'ss'</span></tt>.</li>
<li>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="http://bugs.python.org/issue4966">issue 4966</a>)</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 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"><tt class="xref py py-func docutils literal"><span class="pre">faulthandler.enable()</span></tt></a> to install fault handlers for the
<tt class="xref py py-const docutils literal"><span class="pre">SIGSEGV</span></tt>, <tt class="xref py py-const docutils literal"><span class="pre">SIGFPE</span></tt>, <tt class="xref py py-const docutils literal"><span class="pre">SIGABRT</span></tt>, <tt class="xref py py-const docutils literal"><span class="pre">SIGBUS</span></tt>, and
<tt class="xref py py-const docutils literal"><span class="pre">SIGILL</span></tt> signals. You can also enable them at startup by setting the
<span class="target" id="index-14"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONFAULTHANDLER"><tt class="xref std std-envvar docutils literal"><span class="pre">PYTHONFAULTHANDLER</span></tt></a> environment variable or by using <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><em class="xref std std-option">-X</em></a>
<tt class="docutils literal"><span class="pre">faulthandler</span></tt> command line option.</p>
<p>Example of a segmentation fault on Linux:</p>
<div class="highlight-python3"><pre>$ python -q -X faulthandler
&gt;&gt;&gt; import ctypes
&gt;&gt;&gt; ctypes.string_at(0)
Fatal Python error: Segmentation fault

Current thread 0x00007fb899f39700:
  File "/home/python/cpython/Lib/ctypes/__init__.py", line 486 in string_at
  File "&lt;stdin&gt;", line 1 in &lt;module&gt;
Segmentation fault</pre>
</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."><tt class="xref py py-mod docutils literal"><span class="pre">ipaddress</span></tt></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-15"></span><a class="pep reference external" href="http://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."><tt class="xref py py-mod docutils literal"><span class="pre">lzma</span></tt></a> module provides data compression and decompression
using the LZMA algorithm, including support for the <tt class="docutils literal"><span class="pre">.xz</span></tt> and <tt class="docutils literal"><span class="pre">.lzma</span></tt>
file formats.</p>
<p>(Contributed by Nadeem Vawda and Per Øyvind Karlsen in <a class="reference external" href="http://bugs.python.org/issue6715">issue 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 <tt class="xref py py-attr docutils literal"><span class="pre">__isabstractmethod__</span></tt> as a dynamically updated
property. The built-in descriptors have been updated accordingly.</p>
<blockquote>
<div><ul class="simple">
<li><a class="reference internal" href="../library/abc.html#abc.abstractproperty" title="abc.abstractproperty"><tt class="xref py py-class docutils literal"><span class="pre">abc.abstractproperty</span></tt></a> has been deprecated, use <a class="reference internal" href="../library/functions.html#property" title="property"><tt class="xref py py-class docutils literal"><span class="pre">property</span></tt></a>
with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><tt class="xref py py-func docutils literal"><span class="pre">abc.abstractmethod()</span></tt></a> instead.</li>
<li><a class="reference internal" href="../library/abc.html#abc.abstractclassmethod" title="abc.abstractclassmethod"><tt class="xref py py-class docutils literal"><span class="pre">abc.abstractclassmethod</span></tt></a> has been deprecated, use
<a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><tt class="xref py py-class docutils literal"><span class="pre">classmethod</span></tt></a> with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><tt class="xref py py-func docutils literal"><span class="pre">abc.abstractmethod()</span></tt></a> instead.</li>
<li><a class="reference internal" href="../library/abc.html#abc.abstractstaticmethod" title="abc.abstractstaticmethod"><tt class="xref py py-class docutils literal"><span class="pre">abc.abstractstaticmethod</span></tt></a> has been deprecated, use
<a class="reference internal" href="../library/functions.html#staticmethod" title="staticmethod"><tt class="xref py py-class docutils literal"><span class="pre">staticmethod</span></tt></a> with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><tt class="xref py py-func docutils literal"><span class="pre">abc.abstractmethod()</span></tt></a> instead.</li>
</ul>
</div></blockquote>
<p>(Contributed by Darren Dale in <a class="reference external" href="http://bugs.python.org/issue11610">issue 11610</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."><tt class="xref py py-mod docutils literal"><span class="pre">array</span></tt></a> module supports the <tt class="xref c c-type docutils literal"><span class="pre">long</span> <span class="pre">long</span></tt> type using <tt class="docutils literal"><span class="pre">q</span></tt> and
<tt class="docutils literal"><span class="pre">Q</span></tt> type codes.</p>
<p>(Contributed by Oren Tirosh and Hirokazu Yamamoto in <a class="reference external" href="http://bugs.python.org/issue1172711">issue 1172711</a>)</p>
</div>
<div class="section" id="base64-binascii">
<h3>base64, binascii<a class="headerlink" href="#base64-binascii" title="Permalink to this headline">¶</a></h3>
<p>ASCII-only Unicode strings are now accepted by the decoding functions of the
modern interface. For example, <tt class="docutils literal"><span class="pre">base64.b64decode('YWJj')</span></tt> returns <tt class="docutils literal"><span class="pre">b'abc'</span></tt>.</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."><tt class="xref py py-mod docutils literal"><span class="pre">bz2</span></tt></a> module has been rewritten from scratch. In the process, several
new features have been added:</p>
<ul>
<li><p class="first">New <a class="reference internal" href="../library/bz2.html#bz2.open" title="bz2.open"><tt class="xref py py-func docutils literal"><span class="pre">bz2.open()</span></tt></a> function: open a bzip2-compressed file in binary or
text mode.</p>
</li>
<li><p class="first"><a class="reference internal" href="../library/bz2.html#bz2.BZ2File" title="bz2.BZ2File"><tt class="xref py py-class docutils literal"><span class="pre">bz2.BZ2File</span></tt></a> can now read from and write to arbitrary file-like
objects, by means of its constructor&#8217;s <em>fileobj</em> argument.</p>
<p>(Contributed by Nadeem Vawda in <a class="reference external" href="http://bugs.python.org/issue5863">issue 5863</a>)</p>
</li>
<li><p class="first"><a class="reference internal" href="../library/bz2.html#bz2.BZ2File" title="bz2.BZ2File"><tt class="xref py py-class docutils literal"><span class="pre">bz2.BZ2File</span></tt></a> and <a class="reference internal" href="../library/bz2.html#bz2.decompress" title="bz2.decompress"><tt class="xref py py-func docutils literal"><span class="pre">bz2.decompress()</span></tt></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"><tt class="xref py py-class docutils literal"><span class="pre">bz2.BZ2File</span></tt></a> can now also be used to create this type of file, using
the <tt class="docutils literal"><span class="pre">'a'</span></tt> (append) mode.</p>
<p>(Contributed by Nir Aides in <a class="reference external" href="http://bugs.python.org/issue1625">issue 1625</a>)</p>
</li>
<li><p class="first"><a class="reference internal" href="../library/bz2.html#bz2.BZ2File" title="bz2.BZ2File"><tt class="xref py py-class docutils literal"><span class="pre">bz2.BZ2File</span></tt></a> now implements all of the <a class="reference internal" href="../library/io.html#io.BufferedIOBase" title="io.BufferedIOBase"><tt class="xref py py-class docutils literal"><span class="pre">io.BufferedIOBase</span></tt></a> API,
except for the <tt class="xref py py-meth docutils literal"><span class="pre">detach()</span></tt> and <tt class="xref py py-meth docutils literal"><span class="pre">truncate()</span></tt> 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"><tt class="xref py py-mod docutils literal"><span class="pre">mbcs</span></tt></a> codec has been rewritten to handle correctly
<tt class="docutils literal"><span class="pre">replace</span></tt> and <tt class="docutils literal"><span class="pre">ignore</span></tt> error handlers on all Windows versions.  The
<a class="reference internal" href="../library/codecs.html#module-encodings.mbcs" title="encodings.mbcs: Windows ANSI codepage"><tt class="xref py py-mod docutils literal"><span class="pre">mbcs</span></tt></a> codec now supports all error handlers, instead of only
<tt class="docutils literal"><span class="pre">replace</span></tt> to encode and <tt class="docutils literal"><span class="pre">ignore</span></tt> to decode.</p>
<p>A new Windows-only codec has been added: <tt class="docutils literal"><span class="pre">cp65001</span></tt> (<a class="reference external" href="http://bugs.python.org/issue13216">issue 13216</a>). It is the
Windows code page 65001 (Windows UTF-8, <tt class="docutils literal"><span class="pre">CP_UTF8</span></tt>).  For example, it is used
by <tt class="docutils literal"><span class="pre">sys.stdout</span></tt> if the console output code page is set to cp65001 (e.g., using
<tt class="docutils literal"><span class="pre">chcp</span> <span class="pre">65001</span></tt> command).</p>
<p>Multibyte CJK decoders now resynchronize faster.  They only ignore the first
byte of an invalid byte sequence. For example, <tt class="docutils literal"><span class="pre">b'\xff\n'.decode('gb2312',</span>
<span class="pre">'replace')</span></tt> now returns a <tt class="docutils literal"><span class="pre">\n</span></tt> after the replacement character.</p>
<p>(<a class="reference external" href="http://bugs.python.org/issue12016">issue 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"><pre>$ ./python -q
&gt;&gt;&gt; import codecs
&gt;&gt;&gt; encoder = codecs.getincrementalencoder('hz')('strict')
&gt;&gt;&gt; b''.join(encoder.encode(x) for x in '\u52ff\u65bd\u65bc\u4eba\u3002 Bye.')
b'~{NpJ)l6HK!#~} Bye.'</pre>
</div>
<p>This example gives <tt class="docutils literal"><span class="pre">b'~{Np~}~{J)~}~{l6~}~{HK~}~{!#~}</span> <span class="pre">Bye.'</span></tt> with older Python
versions.</p>
<p>(<a class="reference external" href="http://bugs.python.org/issue12100">issue 12100</a>)</p>
<p>The <tt class="docutils literal"><span class="pre">unicode_internal</span></tt> 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"><tt class="xref py py-class docutils literal"><span class="pre">ChainMap</span></tt></a> class to allow treating a
number of mappings as a single unit.</p>
<p>(Written by Raymond Hettinger for <a class="reference external" href="http://bugs.python.org/issue11089">issue 11089</a>, made public in
<a class="reference external" href="http://bugs.python.org/issue11297">issue 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"><tt class="xref py py-mod docutils literal"><span class="pre">collections.abc</span></tt></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"><tt class="xref py py-mod docutils literal"><span class="pre">collections</span></tt></a> module to preserve existing imports.</p>
<p>(<a class="reference external" href="http://bugs.python.org/issue11085">issue 11085</a>)</p>
</div>
<div class="section" id="contextlib">
<h3>contextlib<a class="headerlink" href="#contextlib" title="Permalink to this headline">¶</a></h3>
<p><tt class="xref py py-class docutils literal"><span class="pre">ExitStack</span></tt> now provides a solid foundation for
programmatic manipulation of context managers and similar cleanup
functionality. Unlike the previous <tt class="docutils literal"><span class="pre">contextlib.nested</span></tt> API (which was
deprecated and removed), the new API is designed to work correctly
regardless of whether context managers acquire their resources in
their <tt class="docutils literal"><span class="pre">__init__</span></tt> method (for example, file objects) or in their
<tt class="docutils literal"><span class="pre">__enter__</span></tt> method (for example, synchronisation objects from the
<a class="reference internal" href="../library/threading.html#module-threading" title="threading: Thread-based parallelism."><tt class="xref py py-mod docutils literal"><span class="pre">threading</span></tt></a> module).</p>
<p>(<a class="reference external" href="http://bugs.python.org/issue13585">issue 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"><tt class="xref py py-func docutils literal"><span class="pre">mksalt()</span></tt></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)"><tt class="xref py py-mod docutils literal"><span class="pre">crypt</span></tt></a> module.</p>
<p>(<a class="reference external" href="http://bugs.python.org/issue10924">issue 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>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)"><tt class="xref py py-mod docutils literal"><span class="pre">curses</span></tt></a> module is linked to the ncursesw library, use Unicode
functions when Unicode strings or characters are passed (e.g.
<tt class="xref c c-func docutils literal"><span class="pre">waddwstr()</span></tt>), and bytes functions otherwise (e.g. <tt class="xref c c-func docutils literal"><span class="pre">waddstr()</span></tt>).</li>
<li>Use the locale encoding instead of <tt class="docutils literal"><span class="pre">utf-8</span></tt> to encode Unicode strings.</li>
<li><tt class="xref py py-class docutils literal"><span class="pre">curses.window</span></tt> has a new <a class="reference internal" href="../library/curses.html#curses.window.encoding" title="curses.window.encoding"><tt class="xref py py-attr docutils literal"><span class="pre">curses.window.encoding</span></tt></a> attribute.</li>
<li>The <tt class="xref py py-class docutils literal"><span class="pre">curses.window</span></tt> class has a new <a class="reference internal" href="../library/curses.html#curses.window.get_wch" title="curses.window.get_wch"><tt class="xref py py-meth docutils literal"><span class="pre">get_wch()</span></tt></a>
method to get a wide character</li>
<li>The <a class="reference internal" href="../library/curses.html#module-curses" title="curses: An interface to the curses library, providing portable terminal handling. (Unix)"><tt class="xref py py-mod docutils literal"><span class="pre">curses</span></tt></a> module has a new <a class="reference internal" href="../library/curses.html#curses.unget_wch" title="curses.unget_wch"><tt class="xref py py-meth docutils literal"><span class="pre">unget_wch()</span></tt></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"><tt class="xref py py-meth docutils literal"><span class="pre">get_wch()</span></tt></a> will return
it</li>
</ul>
</div></blockquote>
<p>(Contributed by Iñigo Serna in <a class="reference external" href="http://bugs.python.org/issue6755">issue 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>Equality comparisons between naive and aware <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><tt class="xref py py-class docutils literal"><span class="pre">datetime</span></tt></a>
instances don&#8217;t raise <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><tt class="xref py py-exc docutils literal"><span class="pre">TypeError</span></tt></a>.</li>
<li>New <a class="reference internal" href="../library/datetime.html#datetime.datetime.timestamp" title="datetime.datetime.timestamp"><tt class="xref py py-meth docutils literal"><span class="pre">datetime.datetime.timestamp()</span></tt></a> method: Return POSIX timestamp
corresponding to the <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><tt class="xref py py-class docutils literal"><span class="pre">datetime</span></tt></a> instance.</li>
<li>The <a class="reference internal" href="../library/datetime.html#datetime.datetime.strftime" title="datetime.datetime.strftime"><tt class="xref py py-meth docutils literal"><span class="pre">datetime.datetime.strftime()</span></tt></a> method supports formatting years
older than 1000.</li>
<li>XXX The <a class="reference internal" href="../library/datetime.html#datetime.datetime.astimezone" title="datetime.datetime.astimezone"><tt class="xref py py-meth docutils literal"><span class="pre">datetime.datetime.astimezone()</span></tt></a> method can now be
called without arguments to convert datetime instance to the system
timezone.</li>
</ul>
</div></blockquote>
</div>
<div class="section" id="decimal">
<h3>decimal<a class="headerlink" href="#decimal" title="Permalink to this headline">¶</a></h3>
<dl class="docutils">
<dt><a class="reference external" href="http://bugs.python.org/issue7652">issue 7652</a> - integrate fast native decimal arithmetic.</dt>
<dd>C-module and libmpdec written by Stefan Krah.</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&#8217;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 border="1" class="docutils">
<colgroup>
<col width="18%" />
<col width="27%" />
<col width="29%" />
<col width="27%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">&nbsp;</th>
<th class="head">decimal.py</th>
<th class="head">_decimal</th>
<th class="head">speedup</th>
</tr>
</thead>
<tbody valign="top">
<tr><td>pi</td>
<td>42.02s</td>
<td>0.345s</td>
<td>120x</td>
</tr>
<tr><td>telco</td>
<td>172.19s</td>
<td>5.68s</td>
<td>30x</td>
</tr>
<tr><td>psycopg</td>
<td>3.57s</td>
<td>0.29s</td>
<td>12x</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>The <a class="reference internal" href="../library/decimal.html#decimal.FloatOperation" title="decimal.FloatOperation"><tt class="xref py py-exc docutils literal"><span class="pre">FloatOperation</span></tt></a> signal optionally enables stricter
semantics for mixing floats and Decimals.</li>
<li>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"><tt class="xref py py-data docutils literal"><span class="pre">HAVE_THREADS</span></tt></a> is set to False.</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 class="first">The C module has the following context limits, depending on the machine
architecture:</p>
<blockquote>
<div><table border="1" class="docutils">
<colgroup>
<col width="27%" />
<col width="30%" />
<col width="43%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">&nbsp;</th>
<th class="head"><p class="first last">32-bit</p>
</th>
<th class="head"><p class="first last">64-bit</p>
</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><p class="first last"><tt class="xref py py-const docutils literal"><span class="pre">MAX_PREC</span></tt></p>
</td>
<td><p class="first last"><tt class="xref py py-const docutils literal"><span class="pre">425000000</span></tt></p>
</td>
<td><p class="first last"><tt class="xref py py-const docutils literal"><span class="pre">999999999999999999</span></tt></p>
</td>
</tr>
<tr><td><p class="first last"><tt class="xref py py-const docutils literal"><span class="pre">MAX_EMAX</span></tt></p>
</td>
<td><p class="first last"><tt class="xref py py-const docutils literal"><span class="pre">425000000</span></tt></p>
</td>
<td><p class="first last"><tt class="xref py py-const docutils literal"><span class="pre">999999999999999999</span></tt></p>
</td>
</tr>
<tr><td><p class="first last"><tt class="xref py py-const docutils literal"><span class="pre">MIN_EMIN</span></tt></p>
</td>
<td><p class="first last"><tt class="xref py py-const docutils literal"><span class="pre">-425000000</span></tt></p>
</td>
<td><p class="first last"><tt class="xref py py-const docutils literal"><span class="pre">-999999999999999999</span></tt></p>
</td>
</tr>
</tbody>
</table>
</div></blockquote>
</li>
<li><p class="first">In the context templates (<a class="reference internal" href="../library/decimal.html#decimal.DefaultContext" title="decimal.DefaultContext"><tt class="xref py py-class docutils literal"><span class="pre">DefaultContext</span></tt></a>,
<a class="reference internal" href="../library/decimal.html#decimal.BasicContext" title="decimal.BasicContext"><tt class="xref py py-class docutils literal"><span class="pre">BasicContext</span></tt></a> and <a class="reference internal" href="../library/decimal.html#decimal.ExtendedContext" title="decimal.ExtendedContext"><tt class="xref py py-class docutils literal"><span class="pre">ExtendedContext</span></tt></a>)
the magnitude of <tt class="xref py py-attr docutils literal"><span class="pre">Emax</span></tt> and
<tt class="xref py py-attr docutils literal"><span class="pre">Emin</span></tt> has changed to <tt class="xref py py-const docutils literal"><span class="pre">999999</span></tt>.</p>
</li>
<li><p class="first">The <a class="reference internal" href="../library/decimal.html#decimal.Decimal" title="decimal.Decimal"><tt class="xref py py-class docutils literal"><span class="pre">Decimal</span></tt></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"><tt class="xref py py-exc docutils literal"><span class="pre">InvalidOperation</span></tt></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"><tt class="xref py py-meth docutils literal"><span class="pre">create_decimal()</span></tt></a>
in order to obtain a rounded or inexact value.</p>
</li>
<li><p class="first">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"><tt class="xref py py-meth docutils literal"><span class="pre">exp()</span></tt></a> and <a class="reference internal" href="../library/decimal.html#decimal.Decimal.ln" title="decimal.Decimal.ln"><tt class="xref py py-meth docutils literal"><span class="pre">ln()</span></tt></a> functions,
but the final result is only &#8220;almost always correctly rounded&#8221;.</p>
</li>
<li><p class="first">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"><tt class="xref py py-class docutils literal"><span class="pre">MutableMapping</span></tt></a>.  For speed reasons,
<tt class="xref py py-attr docutils literal"><span class="pre">flags</span></tt> and <tt class="xref py py-attr docutils literal"><span class="pre">traps</span></tt> always
refer to the same <a class="reference internal" href="../library/collections.abc.html#collections.abc.MutableMapping" title="collections.abc.MutableMapping"><tt class="xref py py-class docutils literal"><span class="pre">MutableMapping</span></tt></a> that the context
was initialized with. If a new signal dictionary is assigned,
<tt class="xref py py-attr docutils literal"><span class="pre">flags</span></tt> and <tt class="xref py py-attr docutils literal"><span class="pre">traps</span></tt>
are updated with the new values, but they do not reference the RHS
dictionary.</p>
</li>
<li><p class="first">Pickling a <a class="reference internal" href="../library/decimal.html#decimal.Context" title="decimal.Context"><tt class="xref py py-class docutils literal"><span class="pre">Context</span></tt></a> produces a different output in order
to have a common interchange format for the Python and C versions.</p>
</li>
<li><p class="first">The order of arguments in the <a class="reference internal" href="../library/decimal.html#decimal.Context" title="decimal.Context"><tt class="xref py py-class docutils literal"><span class="pre">Context</span></tt></a> constructor has been
changed to match the order displayed by <a class="reference internal" href="../library/functions.html#repr" title="repr"><tt class="xref py py-func docutils literal"><span class="pre">repr()</span></tt></a>.</p>
</li>
<li><p class="first">The <tt class="docutils literal"><span class="pre">watchexp</span></tt> parameter in the <a class="reference internal" href="../library/decimal.html#decimal.Decimal.quantize" title="decimal.Decimal.quantize"><tt class="xref py py-meth docutils literal"><span class="pre">quantize()</span></tt></a> method
is deprecated.</p>
</li>
</ul>
</div>
</div>
<div class="section" id="ftplib">
<h3>ftplib<a class="headerlink" href="#ftplib" title="Permalink to this headline">¶</a></h3>
<p>The <a class="reference internal" href="../library/ftplib.html#ftplib.FTP_TLS" title="ftplib.FTP_TLS"><tt class="xref py py-class docutils literal"><span class="pre">FTP_TLS</span></tt></a> class now provides a new
<a class="reference internal" href="../library/ftplib.html#ftplib.FTP_TLS.ccc" title="ftplib.FTP_TLS.ccc"><tt class="xref py py-func docutils literal"><span class="pre">ccc()</span></tt></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.</p>
<p>(Contributed by Giampaolo Rodolà in <a class="reference external" href="http://bugs.python.org/issue12139">issue 12139</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"><tt class="xref py py-data docutils literal"><span class="pre">callbacks</span></tt></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"><tt class="xref py py-func docutils literal"><span class="pre">compare_digest()</span></tt></a> function has been added to prevent
side channel attacks on digests through timing analysis.</p>
<p>(Contributed by Nick Coghlan and Christian Heimes in issue:<cite>15061</cite>)</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"><tt class="xref py py-class docutils literal"><span class="pre">IMAP4_SSL</span></tt></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="http://bugs.python.org/issue8808">issue 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"><tt class="xref py py-func docutils literal"><span class="pre">getclosurevars()</span></tt></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="http://bugs.python.org/issue13062">issue 13062</a>)</p>
<p>A new <a class="reference internal" href="../library/inspect.html#inspect.getgeneratorlocals" title="inspect.getgeneratorlocals"><tt class="xref py py-func docutils literal"><span class="pre">getgeneratorlocals()</span></tt></a> function has been added. This
function reports the current binding of local variables in the generator&#8217;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="http://bugs.python.org/issue15153">issue 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"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> function has a new <tt class="docutils literal"><span class="pre">'x'</span></tt> 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"><tt class="xref py py-exc docutils literal"><span class="pre">FileExistsError</span></tt></a> if the file
already exists. It is based on the C11 &#8216;x&#8217; mode to fopen().</p>
<p>(Contributed by David Townshend in <a class="reference external" href="http://bugs.python.org/issue12760">issue 12760</a>)</p>
<p>The constructor of the <a class="reference internal" href="../library/io.html#io.TextIOWrapper" title="io.TextIOWrapper"><tt class="xref py py-class docutils literal"><span class="pre">TextIOWrapper</span></tt></a> class has a new
<em>write_through</em> optional argument. If <em>write_through</em> is <tt class="xref docutils literal"><span class="pre">True</span></tt>, calls to
<tt class="xref py py-meth docutils literal"><span class="pre">write()</span></tt> are guaranteed not to be buffered: any data
written on the <a class="reference internal" href="../library/io.html#io.TextIOWrapper" title="io.TextIOWrapper"><tt class="xref py py-class docutils literal"><span class="pre">TextIOWrapper</span></tt></a> object is immediately handled to its
underlying binary buffer.</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.)."><tt class="xref py py-mod docutils literal"><span class="pre">math</span></tt></a> module has a new function:</p>
<blockquote>
<div><ul class="simple">
<li><a class="reference internal" href="../library/math.html#math.log2" title="math.log2"><tt class="xref py py-func docutils literal"><span class="pre">log2()</span></tt></a>: return the base-2 logarithm of <em>x</em>
(Written by Mark Dickinson in <a class="reference external" href="http://bugs.python.org/issue11888">issue 11888</a>).</li>
</ul>
</div></blockquote>
</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"><tt class="xref py py-func docutils literal"><span class="pre">multiprocessing.connection.wait()</span></tt></a> function allows to poll
multiple objects (such as connections, sockets and pipes) with a timeout.
(Contributed by Richard Oudkerk in <a class="reference external" href="http://bugs.python.org/issue12328">issue 12328</a>.)</p>
<p><a class="reference internal" href="../library/multiprocessing.html#multiprocessing.Connection" title="multiprocessing.Connection"><tt class="xref py py-class docutils literal"><span class="pre">multiprocessing.Connection</span></tt></a> objects can now be transferred over
multiprocessing connections.
(Contributed by Richard Oudkerk in <a class="reference external" href="http://bugs.python.org/issue4892">issue 4892</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"><tt class="xref py py-class docutils literal"><span class="pre">nntplib.NNTP</span></tt></a> class now supports the context manager protocol to
unconditionally consume <a class="reference internal" href="../library/socket.html#socket.error" title="socket.error"><tt class="xref py py-exc docutils literal"><span class="pre">socket.error</span></tt></a> exceptions and to close the NNTP
connection when done:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">nntplib</span> <span class="k">import</span> <span class="n">NNTP</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">with</span> <span class="n">NNTP</span><span class="p">(</span><span class="s">&#39;news.gmane.org&#39;</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="s">&#39;gmane.comp.python.committers&#39;</span><span class="p">)</span>
<span class="gp">...</span>
<span class="go">(&#39;211 1755 1 1755 gmane.comp.python.committers&#39;, 1755, 1, 1755, &#39;gmane.comp.python.committers&#39;)</span>
<span class="go">&gt;&gt;&gt;</span>
</pre></div>
</div>
<p>(Contributed by Giampaolo Rodolà in <a class="reference external" href="http://bugs.python.org/issue9795">issue 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 class="first">The <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> module has a new <a class="reference internal" href="../library/os.html#os.pipe2" title="os.pipe2"><tt class="xref py py-func docutils literal"><span class="pre">pipe2()</span></tt></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"><tt class="xref py py-data docutils literal"><span class="pre">O_CLOEXEC</span></tt></a> or
<a class="reference internal" href="../library/os.html#os.O_NONBLOCK" title="os.O_NONBLOCK"><tt class="xref py py-data docutils literal"><span class="pre">O_NONBLOCK</span></tt></a> flags set atomically. This is especially useful to
avoid race conditions in multi-threaded programs.</p>
</li>
<li><p class="first">The <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> module has a new <a class="reference internal" href="../library/os.html#os.sendfile" title="os.sendfile"><tt class="xref py py-func docutils literal"><span class="pre">sendfile()</span></tt></a> function which provides
an efficent &#8220;zero-copy&#8221; way for copying data from one file (or socket)
descriptor to another. The phrase &#8220;zero-copy&#8221; 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"><tt class="xref py py-func docutils literal"><span class="pre">sendfile()</span></tt></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="http://bugs.python.org/issue10882">issue 10882</a>.)</p>
</li>
<li><p class="first">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="http://bugs.python.org/issue4761">issue 4761</a>,
<a class="reference external" href="http://bugs.python.org/issue10755">issue 10755</a> and <a class="reference external" href="http://bugs.python.org/issue14626">issue 14626</a>).</p>
<ul class="simple">
<li>The <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> module has a new <a class="reference internal" href="../library/os.html#os.fwalk" title="os.fwalk"><tt class="xref py py-func docutils literal"><span class="pre">fwalk()</span></tt></a> function similar to
<a class="reference internal" href="../library/os.html#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> except that it also yields file descriptors referring to the
directories visited. This is especially useful to avoid symlink races.</li>
<li>The following functions get new optional <em>dir_fd</em> (<a class="reference internal" href="../library/os.html#dir-fd"><em>paths relative to
directory descriptors</em></a>) and/or <em>follow_symlinks</em> (<a class="reference internal" href="../library/os.html#follow-symlinks"><em>not
following symlinks</em></a>):
<a class="reference internal" href="../library/os.html#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.chflags" title="os.chflags"><tt class="xref py py-func docutils literal"><span class="pre">chflags()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.chmod" title="os.chmod"><tt class="xref py py-func docutils literal"><span class="pre">chmod()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.chown" title="os.chown"><tt class="xref py py-func docutils literal"><span class="pre">chown()</span></tt></a>,
<a class="reference internal" href="../library/os.html#os.link" title="os.link"><tt class="xref py py-func docutils literal"><span class="pre">link()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.lstat" title="os.lstat"><tt class="xref py py-func docutils literal"><span class="pre">lstat()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.mkdir" title="os.mkdir"><tt class="xref py py-func docutils literal"><span class="pre">mkdir()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.mkfifo" title="os.mkfifo"><tt class="xref py py-func docutils literal"><span class="pre">mkfifo()</span></tt></a>,
<a class="reference internal" href="../library/os.html#os.mknod" title="os.mknod"><tt class="xref py py-func docutils literal"><span class="pre">mknod()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.readlink" title="os.readlink"><tt class="xref py py-func docutils literal"><span class="pre">readlink()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.remove" title="os.remove"><tt class="xref py py-func docutils literal"><span class="pre">remove()</span></tt></a>,
<a class="reference internal" href="../library/os.html#os.rename" title="os.rename"><tt class="xref py py-func docutils literal"><span class="pre">rename()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.replace" title="os.replace"><tt class="xref py py-func docutils literal"><span class="pre">replace()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.rmdir" title="os.rmdir"><tt class="xref py py-func docutils literal"><span class="pre">rmdir()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a>,
<a class="reference internal" href="../library/os.html#os.symlink" title="os.symlink"><tt class="xref py py-func docutils literal"><span class="pre">symlink()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.unlink" title="os.unlink"><tt class="xref py py-func docutils literal"><span class="pre">unlink()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.utime" title="os.utime"><tt class="xref py py-func docutils literal"><span class="pre">utime()</span></tt></a>.</li>
<li>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"><tt class="xref py py-func docutils literal"><span class="pre">chdir()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.chmod" title="os.chmod"><tt class="xref py py-func docutils literal"><span class="pre">chmod()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.chown" title="os.chown"><tt class="xref py py-func docutils literal"><span class="pre">chown()</span></tt></a>,
<a class="reference internal" href="../library/os.html#os.execve" title="os.execve"><tt class="xref py py-func docutils literal"><span class="pre">execve()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.listdir" title="os.listdir"><tt class="xref py py-func docutils literal"><span class="pre">listdir()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.pathconf" title="os.pathconf"><tt class="xref py py-func docutils literal"><span class="pre">pathconf()</span></tt></a>, <a class="reference internal" href="../library/os.path.html#os.path.exists" title="os.path.exists"><tt class="xref py py-func docutils literal"><span class="pre">exists()</span></tt></a>,
<a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.statvfs" title="os.statvfs"><tt class="xref py py-func docutils literal"><span class="pre">statvfs()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.utime" title="os.utime"><tt class="xref py py-func docutils literal"><span class="pre">utime()</span></tt></a>.</li>
</ul>
</li>
<li><p class="first">The <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> module has two new functions: <a class="reference internal" href="../library/os.html#os.getpriority" title="os.getpriority"><tt class="xref py py-func docutils literal"><span class="pre">getpriority()</span></tt></a> and
<a class="reference internal" href="../library/os.html#os.setpriority" title="os.setpriority"><tt class="xref py py-func docutils literal"><span class="pre">setpriority()</span></tt></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"><tt class="xref py py-func docutils literal"><span class="pre">os.nice()</span></tt></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="http://bugs.python.org/issue10784">issue 10784</a>.)</p>
</li>
<li><p class="first">The new <a class="reference internal" href="../library/os.html#os.replace" title="os.replace"><tt class="xref py py-func docutils literal"><span class="pre">os.replace()</span></tt></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"><tt class="xref py py-func docutils literal"><span class="pre">os.rename()</span></tt></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="http://bugs.python.org/issue8828">issue 8828</a>.)</p>
</li>
<li><p class="first">The stat family of functions (<a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.fstat" title="os.fstat"><tt class="xref py py-func docutils literal"><span class="pre">fstat()</span></tt></a>,
and <a class="reference internal" href="../library/os.html#os.lstat" title="os.lstat"><tt class="xref py py-func docutils literal"><span class="pre">lstat()</span></tt></a>) now support reading a file&#8217;s timestamps
with nanosecond precision.  Symmetrically, <a class="reference internal" href="../library/os.html#os.utime" title="os.utime"><tt class="xref py py-func docutils literal"><span class="pre">utime()</span></tt></a>
can now write file timestamps with nanosecond precision.  (Contributed by
Larry Hastings in <a class="reference external" href="http://bugs.python.org/issue14127">issue 14127</a>.)</p>
</li>
<li><p class="first">The new <a class="reference internal" href="../library/os.html#os.get_terminal_size" title="os.get_terminal_size"><tt class="xref py py-func docutils literal"><span class="pre">os.get_terminal_size()</span></tt></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"><tt class="xref py py-func docutils literal"><span class="pre">shutil.get_terminal_size()</span></tt></a>.
(Contributed by Zbigniew Jędrzejewski-Szmek in <a class="reference external" href="http://bugs.python.org/issue13609">issue 13609</a>.)</p>
</li>
</ul>
<ul class="simple">
<li>New functions to support Linux extended attributes (<a class="reference external" href="http://bugs.python.org/issue12720">issue 12720</a>):
<a class="reference internal" href="../library/os.html#os.getxattr" title="os.getxattr"><tt class="xref py py-func docutils literal"><span class="pre">getxattr()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.listxattr" title="os.listxattr"><tt class="xref py py-func docutils literal"><span class="pre">listxattr()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.removexattr" title="os.removexattr"><tt class="xref py py-func docutils literal"><span class="pre">removexattr()</span></tt></a>,
<a class="reference internal" href="../library/os.html#os.setxattr" title="os.setxattr"><tt class="xref py py-func docutils literal"><span class="pre">setxattr()</span></tt></a>.</li>
<li>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"><tt class="xref py py-func docutils literal"><span class="pre">sched_get_priority_max()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.sched_get_priority_min" title="os.sched_get_priority_min"><tt class="xref py py-func docutils literal"><span class="pre">sched_get_priority_min()</span></tt></a>,
<a class="reference internal" href="../library/os.html#os.sched_getaffinity" title="os.sched_getaffinity"><tt class="xref py py-func docutils literal"><span class="pre">sched_getaffinity()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.sched_getparam" title="os.sched_getparam"><tt class="xref py py-func docutils literal"><span class="pre">sched_getparam()</span></tt></a>,
<a class="reference internal" href="../library/os.html#os.sched_getscheduler" title="os.sched_getscheduler"><tt class="xref py py-func docutils literal"><span class="pre">sched_getscheduler()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.sched_rr_get_interval" title="os.sched_rr_get_interval"><tt class="xref py py-func docutils literal"><span class="pre">sched_rr_get_interval()</span></tt></a>,
<a class="reference internal" href="../library/os.html#os.sched_setaffinity" title="os.sched_setaffinity"><tt class="xref py py-func docutils literal"><span class="pre">sched_setaffinity()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.sched_setparam" title="os.sched_setparam"><tt class="xref py py-func docutils literal"><span class="pre">sched_setparam()</span></tt></a>,
<a class="reference internal" href="../library/os.html#os.sched_setscheduler" title="os.sched_setscheduler"><tt class="xref py py-func docutils literal"><span class="pre">sched_setscheduler()</span></tt></a>, <a class="reference internal" href="../library/os.html#os.sched_yield" title="os.sched_yield"><tt class="xref py py-func docutils literal"><span class="pre">sched_yield()</span></tt></a>,</li>
<li>New functions to control the file system:<ul>
<li><a class="reference internal" href="../library/os.html#os.posix_fadvise" title="os.posix_fadvise"><tt class="xref py py-func docutils literal"><span class="pre">posix_fadvise()</span></tt></a>: Announces an intention to access data in a
specific pattern thus allowing the kernel to make optimizations.</li>
<li><a class="reference internal" href="../library/os.html#os.posix_fallocate" title="os.posix_fallocate"><tt class="xref py py-func docutils literal"><span class="pre">posix_fallocate()</span></tt></a>: Ensures that enough disk space is allocated
for a file.</li>
<li><a class="reference internal" href="../library/os.html#os.sync" title="os.sync"><tt class="xref py py-func docutils literal"><span class="pre">sync()</span></tt></a>: Force write of everything to disk.</li>
</ul>
</li>
<li>Add some extra posix functions to the os module:<ul>
<li><a class="reference internal" href="../library/os.html#os.lockf" title="os.lockf"><tt class="xref py py-func docutils literal"><span class="pre">lockf()</span></tt></a>: Apply, test or remove a POSIX lock on an open file descriptor.</li>
<li><a class="reference internal" href="../library/os.html#os.pread" title="os.pread"><tt class="xref py py-func docutils literal"><span class="pre">pread()</span></tt></a>: Read from a file descriptor at an offset, the file
offset remains unchanged.</li>
<li><a class="reference internal" href="../library/os.html#os.pwrite" title="os.pwrite"><tt class="xref py py-func docutils literal"><span class="pre">pwrite()</span></tt></a>: Write to a file descriptor from an offset, leaving
the file offset unchanged.</li>
<li><a class="reference internal" href="../library/os.html#os.readv" title="os.readv"><tt class="xref py py-func docutils literal"><span class="pre">readv()</span></tt></a>: Read from a file descriptor into a number of writable buffers.</li>
<li><a class="reference internal" href="../library/os.html#os.truncate" title="os.truncate"><tt class="xref py py-func docutils literal"><span class="pre">truncate()</span></tt></a>: Truncate the file corresponding to <em>path</em>, so that
it is at most <em>length</em> bytes in size.</li>
<li><a class="reference internal" href="../library/os.html#os.waitid" title="os.waitid"><tt class="xref py py-func docutils literal"><span class="pre">waitid()</span></tt></a>: Wait for the completion of one or more child processes.</li>
<li><a class="reference internal" href="../library/os.html#os.writev" title="os.writev"><tt class="xref py py-func docutils literal"><span class="pre">writev()</span></tt></a>: Write the contents of <em>buffers</em> to a file descriptor,
where <em>buffers</em> is an arbitrary sequence of buffers.</li>
<li><a class="reference internal" href="../library/os.html#os.getgrouplist" title="os.getgrouplist"><tt class="xref py py-func docutils literal"><span class="pre">getgrouplist()</span></tt></a> (<a class="reference external" href="http://bugs.python.org/issue9344">issue 9344</a>): Return list of group ids that
specified user belongs to.</li>
</ul>
</li>
<li><a class="reference internal" href="../library/os.html#os.times" title="os.times"><tt class="xref py py-func docutils literal"><span class="pre">times()</span></tt></a> and <a class="reference internal" href="../library/os.html#os.uname" title="os.uname"><tt class="xref py py-func docutils literal"><span class="pre">uname()</span></tt></a>: Return type changed from a tuple to
a tuple-like object with named attributes.</li>
</ul>
</div>
<div class="section" id="pdb">
<h3>pdb<a class="headerlink" href="#pdb" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li>Tab-completion is now available not only for command names, but also their
arguments.  For example, for the <tt class="docutils literal"><span class="pre">break</span></tt> command, function and file names
are completed.  (Contributed by Georg Brandl in <a class="reference external" href="http://bugs.python.org/issue14210">issue 14210</a>)</li>
</ul>
</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"><tt class="xref py py-class docutils literal"><span class="pre">pickle.Pickler</span></tt></a> objects now have an optional
<a class="reference internal" href="../library/pickle.html#pickle.Pickler.dispatch_table" title="pickle.Pickler.dispatch_table"><tt class="xref py py-attr docutils literal"><span class="pre">dispatch_table</span></tt></a> attribute allowing to set per-pickler
reduction functions.
(Contributed by Richard Oudkerk in <a class="reference external" href="http://bugs.python.org/issue14166">issue 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 <tt class="xref py py-func docutils literal"><span class="pre">serve()</span></tt> function have been removed from the
<a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><tt class="xref py py-mod docutils literal"><span class="pre">pydoc</span></tt></a> module: <tt class="docutils literal"><span class="pre">pydoc</span> <span class="pre">-g</span></tt> and <tt class="xref py py-func docutils literal"><span class="pre">serve()</span></tt> 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/functions.html#str" title="str"><tt class="xref py py-class docutils literal"><span class="pre">str</span></tt></a> regular expressions now support <tt class="docutils literal"><span class="pre">\u</span></tt> and <tt class="docutils literal"><span class="pre">\U</span></tt> escapes.</p>
<p>(Contributed by Serhiy Storchaka in <a class="reference external" href="http://bugs.python.org/issue3665">issue 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><a class="reference internal" href="../library/sched.html#sched.scheduler.run" title="sched.scheduler.run"><tt class="xref py py-meth docutils literal"><span class="pre">run()</span></tt></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"><tt class="xref py py-class docutils literal"><span class="pre">scheduler</span></tt></a> in
non-blocking applications.  (Contributed by Giampaolo Rodolà in <a class="reference external" href="http://bugs.python.org/issue13449">issue 13449</a>)</li>
<li><a class="reference internal" href="../library/sched.html#sched.scheduler" title="sched.scheduler"><tt class="xref py py-class docutils literal"><span class="pre">scheduler</span></tt></a> class can now be safely used in multi-threaded
environments.  (Contributed by Josiah Carlson and Giampaolo Rodolà in
<a class="reference external" href="http://bugs.python.org/issue8684">issue 8684</a>)</li>
<li><em>timefunc</em> and <em>delayfunct</em> parameters of <a class="reference internal" href="../library/sched.html#sched.scheduler" title="sched.scheduler"><tt class="xref py py-class docutils literal"><span class="pre">scheduler</span></tt></a> class
constructor are now optional and defaults to <a class="reference internal" href="../library/time.html#time.time" title="time.time"><tt class="xref py py-func docutils literal"><span class="pre">time.time()</span></tt></a> and
<a class="reference internal" href="../library/time.html#time.sleep" title="time.sleep"><tt class="xref py py-func docutils literal"><span class="pre">time.sleep()</span></tt></a> respectively.  (Contributed by Chris Clark in
<a class="reference external" href="http://bugs.python.org/issue13245">issue 13245</a>)</li>
<li><a class="reference internal" href="../library/sched.html#sched.scheduler.enter" title="sched.scheduler.enter"><tt class="xref py py-meth docutils literal"><span class="pre">enter()</span></tt></a> and <a class="reference internal" href="../library/sched.html#sched.scheduler.enterabs" title="sched.scheduler.enterabs"><tt class="xref py py-meth docutils literal"><span class="pre">enterabs()</span></tt></a>
<em>argument</em> parameter is now optional.  (Contributed by Chris Clark in
<a class="reference external" href="http://bugs.python.org/issue13245">issue 13245</a>)</li>
<li><a class="reference internal" href="../library/sched.html#sched.scheduler.enter" title="sched.scheduler.enter"><tt class="xref py py-meth docutils literal"><span class="pre">enter()</span></tt></a> and <a class="reference internal" href="../library/sched.html#sched.scheduler.enterabs" title="sched.scheduler.enterabs"><tt class="xref py py-meth docutils literal"><span class="pre">enterabs()</span></tt></a>
now accept a <em>kwargs</em> parameter.  (Contributed by Chris Clark in
<a class="reference external" href="http://bugs.python.org/issue13245">issue 13245</a>)</li>
</ul>
</div>
<div class="section" id="shutil">
<h3>shutil<a class="headerlink" href="#shutil" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li>The <a class="reference internal" href="../library/shutil.html#module-shutil" title="shutil: High-level file operations, including copying."><tt class="xref py py-mod docutils literal"><span class="pre">shutil</span></tt></a> module has these new fuctions:<ul>
<li><a class="reference internal" href="../library/shutil.html#shutil.disk_usage" title="shutil.disk_usage"><tt class="xref py py-func docutils literal"><span class="pre">disk_usage()</span></tt></a>: provides total, used and free disk space
statistics. (Contributed by Giampaolo Rodolà in <a class="reference external" href="http://bugs.python.org/issue12442">issue 12442</a>)</li>
<li><a class="reference internal" href="../library/shutil.html#shutil.chown" title="shutil.chown"><tt class="xref py py-func docutils literal"><span class="pre">chown()</span></tt></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="http://bugs.python.org/issue12191">issue 12191</a>)</li>
</ul>
</li>
<li><a class="reference internal" href="../library/shutil.html#shutil.copy2" title="shutil.copy2"><tt class="xref py py-func docutils literal"><span class="pre">copy2()</span></tt></a> and <a class="reference internal" href="../library/shutil.html#shutil.copystat" title="shutil.copystat"><tt class="xref py py-func docutils literal"><span class="pre">copystat()</span></tt></a> now preserve file
timestamps with nanosecond precision on platforms that support it.
They also preserve file &#8220;extended attributes&#8221; on Linux.  (Contributed
by Larry Hastings in <a class="reference external" href="http://bugs.python.org/issue14127">issue 14127</a> and  <a class="reference external" href="http://bugs.python.org/issue15238">issue 15238</a>.)</li>
<li>The new <a class="reference internal" href="../library/shutil.html#shutil.get_terminal_size" title="shutil.get_terminal_size"><tt class="xref py py-func docutils literal"><span class="pre">shutil.get_terminal_size()</span></tt></a> function returns the size of the
terminal window the interpreter is attached to.
(Contributed by Zbigniew Jędrzejewski-Szmek in <a class="reference external" href="http://bugs.python.org/issue13609">issue 13609</a>.)</li>
<li>Several functions now take an optional <tt class="docutils literal"><span class="pre">symlinks</span></tt> argument: when that
parameter is true, symlinks aren&#8217;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="http://bugs.python.org/issue12715">issue 12715</a>.)</li>
<li><a class="reference internal" href="../library/shutil.html#shutil.rmtree" title="shutil.rmtree"><tt class="xref py py-func docutils literal"><span class="pre">rmtree()</span></tt></a> is now resistant to symlink attacks on platforms
which support the new <tt class="docutils literal"><span class="pre">dir_fd</span></tt> parameter in <a class="reference internal" href="../library/os.html#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a> and
<a class="reference internal" href="../library/os.html#os.unlink" title="os.unlink"><tt class="xref py py-func docutils literal"><span class="pre">os.unlink()</span></tt></a>. (Contributed by Martin von Löwis and Hynek Schlawack
in <a class="reference external" href="http://bugs.python.org/issue4489">issue 4489</a>.)</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>The <a class="reference internal" href="../library/signal.html#module-signal" title="signal: Set handlers for asynchronous events."><tt class="xref py py-mod docutils literal"><span class="pre">signal</span></tt></a> module has new functions:<ul>
<li><a class="reference internal" href="../library/signal.html#signal.pthread_sigmask" title="signal.pthread_sigmask"><tt class="xref py py-func docutils literal"><span class="pre">pthread_sigmask()</span></tt></a>: fetch and/or change the signal mask of the
calling thread (Contributed by Jean-Paul Calderone in <a class="reference external" href="http://bugs.python.org/issue8407">issue 8407</a>) ;</li>
<li><a class="reference internal" href="../library/signal.html#signal.pthread_kill" title="signal.pthread_kill"><tt class="xref py py-func docutils literal"><span class="pre">pthread_kill()</span></tt></a>: send a signal to a thread ;</li>
<li><a class="reference internal" href="../library/signal.html#signal.sigpending" title="signal.sigpending"><tt class="xref py py-func docutils literal"><span class="pre">sigpending()</span></tt></a>: examine pending functions ;</li>
<li><a class="reference internal" href="../library/signal.html#signal.sigwait" title="signal.sigwait"><tt class="xref py py-func docutils literal"><span class="pre">sigwait()</span></tt></a>: wait a signal.</li>
<li><a class="reference internal" href="../library/signal.html#signal.sigwaitinfo" title="signal.sigwaitinfo"><tt class="xref py py-func docutils literal"><span class="pre">sigwaitinfo()</span></tt></a>: wait for a signal, returning detailed
information about it.</li>
<li><a class="reference internal" href="../library/signal.html#signal.sigtimedwait" title="signal.sigtimedwait"><tt class="xref py py-func docutils literal"><span class="pre">sigtimedwait()</span></tt></a>: like <a class="reference internal" href="../library/signal.html#signal.sigwaitinfo" title="signal.sigwaitinfo"><tt class="xref py py-func docutils literal"><span class="pre">sigwaitinfo()</span></tt></a> but with a
timeout.</li>
</ul>
</li>
<li>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.</li>
<li><a class="reference internal" href="../library/signal.html#signal.signal" title="signal.signal"><tt class="xref py py-func docutils literal"><span class="pre">signal.signal()</span></tt></a> and <a class="reference internal" href="../library/signal.html#signal.siginterrupt" title="signal.siginterrupt"><tt class="xref py py-func docutils literal"><span class="pre">signal.siginterrupt()</span></tt></a> raise an OSError,
instead of a RuntimeError: OSError has an errno attribute.</li>
</ul>
</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_SSL" title="smtplib.SMTP_SSL"><tt class="xref py py-class docutils literal"><span class="pre">SMTP_SSL</span></tt></a> constructor and the <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP.starttls" title="smtplib.SMTP.starttls"><tt class="xref py py-meth docutils literal"><span class="pre">starttls()</span></tt></a>
method now accept an SSLContext parameter to control parameters of the secure
channel.</p>
<p>(Contributed by Kasun Herath in <a class="reference external" href="http://bugs.python.org/issue8809">issue 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 class="first">The <a class="reference internal" href="../library/socket.html#socket.socket" title="socket.socket"><tt class="xref py py-class docutils literal"><span class="pre">socket</span></tt></a> class now exposes additional methods to process
ancillary data when supported by the underlying platform:</p>
<ul class="simple">
<li><a class="reference internal" href="../library/socket.html#socket.socket.sendmsg" title="socket.socket.sendmsg"><tt class="xref py py-func docutils literal"><span class="pre">sendmsg()</span></tt></a></li>
<li><a class="reference internal" href="../library/socket.html#socket.socket.recvmsg" title="socket.socket.recvmsg"><tt class="xref py py-func docutils literal"><span class="pre">recvmsg()</span></tt></a></li>
<li><a class="reference internal" href="../library/socket.html#socket.socket.recvmsg_into" title="socket.socket.recvmsg_into"><tt class="xref py py-func docutils literal"><span class="pre">recvmsg_into()</span></tt></a></li>
</ul>
<p>(Contributed by David Watson in <a class="reference external" href="http://bugs.python.org/issue6560">issue 6560</a>, based on an earlier patch by
Heiko Wundram)</p>
</li>
<li><p class="first">The <a class="reference internal" href="../library/socket.html#socket.socket" title="socket.socket"><tt class="xref py py-class docutils literal"><span class="pre">socket</span></tt></a> class now supports the PF_CAN protocol family
(<a class="reference external" href="http://en.wikipedia.org/wiki/Socketcan">http://en.wikipedia.org/wiki/Socketcan</a>), on Linux
(<a class="reference external" href="http://lwn.net/Articles/253425">http://lwn.net/Articles/253425</a>).</p>
<p>(Contributed by Matthias Fuchs, updated by Tiago Gonçalves in <a class="reference external" href="http://bugs.python.org/issue10141">issue 10141</a>)</p>
</li>
<li><p class="first">The <a class="reference internal" href="../library/socket.html#socket.socket" title="socket.socket"><tt class="xref py py-class docutils literal"><span class="pre">socket</span></tt></a> class now supports the PF_RDS protocol family
(<a class="reference external" href="http://en.wikipedia.org/wiki/Reliable_Datagram_Sockets">http://en.wikipedia.org/wiki/Reliable_Datagram_Sockets</a> and
<a class="reference external" href="http://oss.oracle.com/projects/rds/">http://oss.oracle.com/projects/rds/</a>).</p>
</li>
</ul>
</div>
<div class="section" id="ssl">
<h3>ssl<a class="headerlink" href="#ssl" title="Permalink to this headline">¶</a></h3>
<ul>
<li><p class="first">The <a class="reference internal" href="../library/ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><tt class="xref py py-mod docutils literal"><span class="pre">ssl</span></tt></a> module has two new random generation functions:</p>
<ul class="simple">
<li><a class="reference internal" href="../library/ssl.html#ssl.RAND_bytes" title="ssl.RAND_bytes"><tt class="xref py py-func docutils literal"><span class="pre">RAND_bytes()</span></tt></a>: generate cryptographically strong
pseudo-random bytes.</li>
<li><a class="reference internal" href="../library/ssl.html#ssl.RAND_pseudo_bytes" title="ssl.RAND_pseudo_bytes"><tt class="xref py py-func docutils literal"><span class="pre">RAND_pseudo_bytes()</span></tt></a>: generate pseudo-random bytes.</li>
</ul>
<p>(Contributed by Victor Stinner in <a class="reference external" href="http://bugs.python.org/issue12049">issue 12049</a>)</p>
</li>
<li><p class="first">The <a class="reference internal" href="../library/ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><tt class="xref py py-mod docutils literal"><span class="pre">ssl</span></tt></a> module now exposes a finer-grained exception hierarchy
in order to make it easier to inspect the various kinds of errors.</p>
<p>(Contributed by Antoine Pitrou in <a class="reference external" href="http://bugs.python.org/issue11183">issue 11183</a>)</p>
</li>
<li><p class="first"><a class="reference internal" href="../library/ssl.html#ssl.SSLContext.load_cert_chain" title="ssl.SSLContext.load_cert_chain"><tt class="xref py py-meth docutils literal"><span class="pre">load_cert_chain()</span></tt></a> now accepts a <em>password</em> argument
to be used if the private key is encrypted.</p>
<p>(Contributed by Adam Simpkins in <a class="reference external" href="http://bugs.python.org/issue12803">issue 12803</a>)</p>
</li>
<li><p class="first">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"><tt class="xref py py-meth docutils literal"><span class="pre">load_dh_params()</span></tt></a> and
<a class="reference internal" href="../library/ssl.html#ssl.SSLContext.set_ecdh_curve" title="ssl.SSLContext.set_ecdh_curve"><tt class="xref py py-meth docutils literal"><span class="pre">set_ecdh_curve()</span></tt></a> methods.</p>
<p>(Contributed by Antoine Pitrou in <a class="reference external" href="http://bugs.python.org/issue13626">issue 13626</a> and <a class="reference external" href="http://bugs.python.org/issue13627">issue 13627</a>)</p>
</li>
<li><p class="first">SSL sockets have a new <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.get_channel_binding" title="ssl.SSLSocket.get_channel_binding"><tt class="xref py py-meth docutils literal"><span class="pre">get_channel_binding()</span></tt></a> method
allowing the implementation of certain authentication mechanisms such as
SCRAM-SHA-1-PLUS.</p>
<p>(Contributed by Jacek Konieczny in <a class="reference external" href="http://bugs.python.org/issue12551">issue 12551</a>)</p>
</li>
<li><p class="first">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"><tt class="xref py py-meth docutils literal"><span class="pre">compression()</span></tt></a> method.</p>
<p>(Contributed by Antoine Pitrou in <a class="reference external" href="http://bugs.python.org/issue13634">issue 13634</a>)</p>
</li>
<li><p class="first">Support has been added for the Next Procotol Negotiation extension using
the <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.set_npn_protocols" title="ssl.SSLContext.set_npn_protocols"><tt class="xref py py-meth docutils literal"><span class="pre">ssl.SSLContext.set_npn_protocols()</span></tt></a> method.</p>
<p>(Contributed by Colin Marc in <a class="reference external" href="http://bugs.python.org/issue14204">issue 14204</a>)</p>
</li>
<li><p class="first">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"><tt class="xref py py-attr docutils literal"><span class="pre">library</span></tt></a> and <a class="reference internal" href="../library/ssl.html#ssl.SSLError.reason" title="ssl.SSLError.reason"><tt class="xref py py-attr docutils literal"><span class="pre">reason</span></tt></a> attributes.</p>
<p>(Contributed by Antoine Pitrou in <a class="reference external" href="http://bugs.python.org/issue14837">issue 14837</a>)</p>
</li>
</ul>
</div>
<div class="section" id="stat">
<h3>stat<a class="headerlink" href="#stat" title="Permalink to this headline">¶</a></h3>
<ul>
<li><p class="first">The undocumented tarfile.filemode function has been moved to
<a class="reference internal" href="../library/stat.html#stat.filemode" title="stat.filemode"><tt class="xref py py-func docutils literal"><span class="pre">stat.filemode()</span></tt></a>. It can be used to convert a file&#8217;s mode to a string of
the form &#8216;-rwxrwxrwx&#8217;.</p>
<p>(Contributed by Giampaolo Rodolà in <a class="reference external" href="http://bugs.python.org/issue14807">issue 14807</a>)</p>
</li>
</ul>
</div>
<div class="section" id="sys">
<h3>sys<a class="headerlink" href="#sys" title="Permalink to this headline">¶</a></h3>
<ul>
<li><p class="first">The <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><tt class="xref py py-mod docutils literal"><span class="pre">sys</span></tt></a> module has a new <a class="reference internal" href="../library/sys.html#sys.thread_info" title="sys.thread_info"><tt class="xref py py-data docutils literal"><span class="pre">thread_info</span></tt></a> <a class="reference internal" href="../glossary.html#term-struct-sequence"><em class="xref std std-term">struct
sequence</em></a> holding informations about the thread implementation.</p>
<p>(<a class="reference external" href="http://bugs.python.org/issue11223">issue 11223</a>)</p>
</li>
</ul>
</div>
<div class="section" id="textwrap">
<h3>textwrap<a class="headerlink" href="#textwrap" title="Permalink to this headline">¶</a></h3>
<ul>
<li><p class="first">The <a class="reference internal" href="../library/textwrap.html#module-textwrap" title="textwrap: Text wrapping and filling"><tt class="xref py py-mod docutils literal"><span class="pre">textwrap</span></tt></a> module has a new <a class="reference internal" href="../library/textwrap.html#textwrap.indent" title="textwrap.indent"><tt class="xref py py-func docutils literal"><span class="pre">indent()</span></tt></a> that makes
it straightforward to add a common prefix to selected lines in a block
of text.</p>
<p>(<a class="reference external" href="http://bugs.python.org/issue13857">issue 13857</a>)</p>
</li>
</ul>
</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-16"></span><a class="pep reference external" href="http://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."><tt class="xref py py-mod docutils literal"><span class="pre">time</span></tt></a> module:</p>
<ul class="simple">
<li><a class="reference internal" href="../library/time.html#time.get_clock_info" title="time.get_clock_info"><tt class="xref py py-func docutils literal"><span class="pre">get_clock_info()</span></tt></a>: Get information on a clock.</li>
<li><a class="reference internal" href="../library/time.html#time.monotonic" title="time.monotonic"><tt class="xref py py-func docutils literal"><span class="pre">monotonic()</span></tt></a>: Monotonic clock (cannot go backward), not affected
by system clock updates.</li>
<li><a class="reference internal" href="../library/time.html#time.perf_counter" title="time.perf_counter"><tt class="xref py py-func docutils literal"><span class="pre">perf_counter()</span></tt></a>: Performance counter with the highest available
resolution to measure a short duration.</li>
<li><a class="reference internal" href="../library/time.html#time.process_time" title="time.process_time"><tt class="xref py py-func docutils literal"><span class="pre">process_time()</span></tt></a>: Sum of the system and user CPU time of the
current process.</li>
</ul>
<p>Other new functions:</p>
<ul class="simple">
<li><a class="reference internal" href="../library/time.html#time.clock_getres" title="time.clock_getres"><tt class="xref py py-func docutils literal"><span class="pre">clock_getres()</span></tt></a>, <a class="reference internal" href="../library/time.html#time.clock_gettime" title="time.clock_gettime"><tt class="xref py py-func docutils literal"><span class="pre">clock_gettime()</span></tt></a> and
<a class="reference internal" href="../library/time.html#time.clock_settime" title="time.clock_settime"><tt class="xref py py-func docutils literal"><span class="pre">clock_settime()</span></tt></a> functions with <tt class="docutils literal"><span class="pre">CLOCK_xxx</span></tt> constants.
(Contributed by Victor Stinner in <a class="reference external" href="http://bugs.python.org/issue10278">issue 10278</a>)</li>
</ul>
</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"><tt class="xref py py-class docutils literal"><span class="pre">types.MappingProxyType</span></tt></a> class: Read-only proxy of a mapping.
(<a class="reference external" href="http://bugs.python.org/issue14386">issue 14386</a>)</p>
<p>The new functions <cite>types.new_class</cite> and <cite>types.prepare_class</cite> provide support
for PEP 3115 compliant dynamic type creation. (<a class="reference external" href="http://bugs.python.org/issue14588">issue 14588</a>)</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"><tt class="xref py py-class docutils literal"><span class="pre">Request</span></tt></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"><tt class="xref py py-meth docutils literal"><span class="pre">get_method()</span></tt></a> to determine what HTTP method
should be used.  For example, this will send a <tt class="docutils literal"><span class="pre">'HEAD'</span></tt> request:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">urlopen</span><span class="p">(</span><span class="n">Request</span><span class="p">(</span><span class="s">&#39;http://www.python.org&#39;</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s">&#39;HEAD&#39;</span><span class="p">))</span>
</pre></div>
</div>
<p>(<a class="reference external" href="http://bugs.python.org/issue1673007">issue 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."><tt class="xref py py-mod docutils literal"><span class="pre">webbrowser</span></tt></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) as
well as the 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.</p>
<p>(<a class="reference external" href="http://bugs.python.org/issue13620">issue 13620</a> and <a class="reference external" href="http://bugs.python.org/issue14493">issue 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."><tt class="xref py py-mod docutils literal"><span class="pre">xml.etree.ElementTree</span></tt></a> module now imports its C accelerator by
default; there is no longer a need to explicitly import
<tt class="xref py py-mod docutils literal"><span class="pre">xml.etree.cElementTree</span></tt> (this module stays for backwards compatibility,
but is now deprecated).  In addition,  the <tt class="docutils literal"><span class="pre">iter</span></tt> family of methods of
<a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.Element" title="xml.etree.ElementTree.Element"><tt class="xref py py-class docutils literal"><span class="pre">Element</span></tt></a> has been optimized (rewritten in C).
The module&#8217;s documentation has also been greatly improved with added examples
and a more detailed reference.</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 class="first">Thanks to <span class="target" id="index-17"></span><a class="pep reference external" href="http://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>the memory footprint is divided by 2 to 4 depending on the text</li>
<li>encode an ASCII string to UTF-8 doesn&#8217;t need to encode characters anymore,
the UTF-8 representation is shared with the ASCII representation</li>
<li>the UTF-8 encoder has been optimized</li>
<li>repeating a single ASCII letter and getting a substring of a ASCII strings
is 4 times faster</li>
</ul>
</li>
<li><p class="first">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="http://bugs.python.org/issue14624">issue 14624</a>, <a class="reference external" href="http://bugs.python.org/issue14738">issue 14738</a> and
<a class="reference external" href="http://bugs.python.org/issue15026">issue 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&#8217;s build process and to the C API include:</p>
<ul class="simple">
<li>New <span class="target" id="index-18"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-3118"><strong>PEP 3118</strong></a> related function:<ul>
<li><a class="reference internal" href="../c-api/memoryview.html#PyMemoryView_FromMemory" title="PyMemoryView_FromMemory"><tt class="xref c c-func docutils literal"><span class="pre">PyMemoryView_FromMemory()</span></tt></a></li>
</ul>
</li>
<li><span class="target" id="index-19"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-0393"><strong>PEP 393</strong></a> added new Unicode types, macros and functions:<ul>
<li>High-level API:<ul>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_CopyCharacters" title="PyUnicode_CopyCharacters"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_CopyCharacters()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_FindChar" title="PyUnicode_FindChar"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_FindChar()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_GetLength" title="PyUnicode_GetLength"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_GetLength()</span></tt></a>, <a class="reference internal" href="../c-api/unicode.html#PyUnicode_GET_LENGTH" title="PyUnicode_GET_LENGTH"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_GET_LENGTH</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_New" title="PyUnicode_New"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_New()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_Substring" title="PyUnicode_Substring"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_Substring()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_ReadChar" title="PyUnicode_ReadChar"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_ReadChar()</span></tt></a>, <a class="reference internal" href="../c-api/unicode.html#PyUnicode_WriteChar" title="PyUnicode_WriteChar"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_WriteChar()</span></tt></a></li>
</ul>
</li>
<li>Low-level API:<ul>
<li><a class="reference internal" href="../c-api/unicode.html#Py_UCS1" title="Py_UCS1"><tt class="xref c c-type docutils literal"><span class="pre">Py_UCS1</span></tt></a>, <a class="reference internal" href="../c-api/unicode.html#Py_UCS2" title="Py_UCS2"><tt class="xref c c-type docutils literal"><span class="pre">Py_UCS2</span></tt></a>, <a class="reference internal" href="../c-api/unicode.html#Py_UCS4" title="Py_UCS4"><tt class="xref c c-type docutils literal"><span class="pre">Py_UCS4</span></tt></a> types</li>
<li><a class="reference internal" href="../c-api/unicode.html#PyASCIIObject" title="PyASCIIObject"><tt class="xref c c-type docutils literal"><span class="pre">PyASCIIObject</span></tt></a> and <a class="reference internal" href="../c-api/unicode.html#PyCompactUnicodeObject" title="PyCompactUnicodeObject"><tt class="xref c c-type docutils literal"><span class="pre">PyCompactUnicodeObject</span></tt></a> structures</li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_READY" title="PyUnicode_READY"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_READY</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_FromKindAndData" title="PyUnicode_FromKindAndData"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_FromKindAndData()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_AsUCS4" title="PyUnicode_AsUCS4"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsUCS4()</span></tt></a>, <a class="reference internal" href="../c-api/unicode.html#PyUnicode_AsUCS4Copy" title="PyUnicode_AsUCS4Copy"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsUCS4Copy()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_DATA" title="PyUnicode_DATA"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_DATA</span></tt></a>, <a class="reference internal" href="../c-api/unicode.html#PyUnicode_1BYTE_DATA" title="PyUnicode_1BYTE_DATA"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_1BYTE_DATA</span></tt></a>,
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_2BYTE_DATA" title="PyUnicode_2BYTE_DATA"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_2BYTE_DATA</span></tt></a>, <a class="reference internal" href="../c-api/unicode.html#PyUnicode_4BYTE_DATA" title="PyUnicode_4BYTE_DATA"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_4BYTE_DATA</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_KIND" title="PyUnicode_KIND"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_KIND</span></tt></a> with <tt class="xref c c-type docutils literal"><span class="pre">PyUnicode_Kind</span></tt> enum:
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_WCHAR_KIND" title="PyUnicode_WCHAR_KIND"><tt class="xref c c-data docutils literal"><span class="pre">PyUnicode_WCHAR_KIND</span></tt></a>, <a class="reference internal" href="../c-api/unicode.html#PyUnicode_1BYTE_KIND" title="PyUnicode_1BYTE_KIND"><tt class="xref c c-data docutils literal"><span class="pre">PyUnicode_1BYTE_KIND</span></tt></a>,
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_2BYTE_KIND" title="PyUnicode_2BYTE_KIND"><tt class="xref c c-data docutils literal"><span class="pre">PyUnicode_2BYTE_KIND</span></tt></a>, <a class="reference internal" href="../c-api/unicode.html#PyUnicode_4BYTE_KIND" title="PyUnicode_4BYTE_KIND"><tt class="xref c c-data docutils literal"><span class="pre">PyUnicode_4BYTE_KIND</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_READ" title="PyUnicode_READ"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_READ</span></tt></a>, <a class="reference internal" href="../c-api/unicode.html#PyUnicode_READ_CHAR" title="PyUnicode_READ_CHAR"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_READ_CHAR</span></tt></a>, <a class="reference internal" href="../c-api/unicode.html#PyUnicode_WRITE" title="PyUnicode_WRITE"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_WRITE</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_MAX_CHAR_VALUE" title="PyUnicode_MAX_CHAR_VALUE"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_MAX_CHAR_VALUE</span></tt></a></li>
</ul>
</li>
</ul>
</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 <tt class="docutils literal"><span class="pre">COMSPEC</span></tt> to <tt class="docutils literal"><span class="pre">command.com</span></tt>
are no longer supported due to maintenance burden.</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>The <tt class="docutils literal"><span class="pre">unicode_internal</span></tt> codec has been deprecated because of the
<span class="target" id="index-20"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-0393"><strong>PEP 393</strong></a>, use UTF-8, UTF-16 (<tt class="docutils literal"><span class="pre">utf-16-le</span></tt> or <tt class="docutils literal"><span class="pre">utf-16-be</span></tt>), or UTF-32
(<tt class="docutils literal"><span class="pre">utf-32-le</span></tt> or <tt class="docutils literal"><span class="pre">utf-32-be</span></tt>)</li>
<li><a class="reference internal" href="../library/ftplib.html#ftplib.FTP.nlst" title="ftplib.FTP.nlst"><tt class="xref py py-meth docutils literal"><span class="pre">ftplib.FTP.nlst()</span></tt></a> and <a class="reference internal" href="../library/ftplib.html#ftplib.FTP.dir" title="ftplib.FTP.dir"><tt class="xref py py-meth docutils literal"><span class="pre">ftplib.FTP.dir()</span></tt></a>: use
<a class="reference internal" href="../library/ftplib.html#ftplib.FTP.mlsd" title="ftplib.FTP.mlsd"><tt class="xref py py-meth docutils literal"><span class="pre">ftplib.FTP.mlsd()</span></tt></a></li>
<li><a class="reference internal" href="../library/platform.html#platform.popen" title="platform.popen"><tt class="xref py py-func docutils literal"><span class="pre">platform.popen()</span></tt></a>: use the <a class="reference internal" href="../library/subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module. Check especially
the <a class="reference internal" href="../library/subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section.</li>
<li><a class="reference external" href="http://bugs.python.org/issue13374">issue 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."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a>
module. Use Unicode filenames, instead of bytes filenames, to not depend on
the ANSI code page anymore and to support any filename.</li>
<li><a class="reference external" href="http://bugs.python.org/issue13988">issue 13988</a>: The <tt class="xref py py-mod docutils literal"><span class="pre">xml.etree.cElementTree</span></tt> module is deprecated.  The
accelerator is used automatically whenever available.</li>
<li>The behaviour of <a class="reference internal" href="../library/time.html#time.clock" title="time.clock"><tt class="xref py py-func docutils literal"><span class="pre">time.clock()</span></tt></a> depends on the platform: use the new
<a class="reference internal" href="../library/time.html#time.perf_counter" title="time.perf_counter"><tt class="xref py py-func docutils literal"><span class="pre">time.perf_counter()</span></tt></a> or <a class="reference internal" href="../library/time.html#time.process_time" title="time.process_time"><tt class="xref py py-func docutils literal"><span class="pre">time.process_time()</span></tt></a> function instead,
depending on your requirements, to have a well defined behaviour.</li>
<li>The <a class="reference internal" href="../library/os.html#os.stat_float_times" title="os.stat_float_times"><tt class="xref py py-func docutils literal"><span class="pre">os.stat_float_times()</span></tt></a> function is deprecated.</li>
<li><a class="reference internal" href="../library/abc.html#module-abc" title="abc: Abstract base classes according to PEP 3119."><tt class="xref py py-mod docutils literal"><span class="pre">abc</span></tt></a> module:<ul>
<li><a class="reference internal" href="../library/abc.html#abc.abstractproperty" title="abc.abstractproperty"><tt class="xref py py-class docutils literal"><span class="pre">abc.abstractproperty</span></tt></a> has been deprecated, use <a class="reference internal" href="../library/functions.html#property" title="property"><tt class="xref py py-class docutils literal"><span class="pre">property</span></tt></a>
with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><tt class="xref py py-func docutils literal"><span class="pre">abc.abstractmethod()</span></tt></a> instead.</li>
<li><a class="reference internal" href="../library/abc.html#abc.abstractclassmethod" title="abc.abstractclassmethod"><tt class="xref py py-class docutils literal"><span class="pre">abc.abstractclassmethod</span></tt></a> has been deprecated, use
<a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><tt class="xref py py-class docutils literal"><span class="pre">classmethod</span></tt></a> with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><tt class="xref py py-func docutils literal"><span class="pre">abc.abstractmethod()</span></tt></a> instead.</li>
<li><a class="reference internal" href="../library/abc.html#abc.abstractstaticmethod" title="abc.abstractstaticmethod"><tt class="xref py py-class docutils literal"><span class="pre">abc.abstractstaticmethod</span></tt></a> has been deprecated, use
<a class="reference internal" href="../library/functions.html#staticmethod" title="staticmethod"><tt class="xref py py-class docutils literal"><span class="pre">staticmethod</span></tt></a> with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><tt class="xref py py-func docutils literal"><span class="pre">abc.abstractmethod()</span></tt></a> instead.</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#Py_UNICODE" title="Py_UNICODE"><tt class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></tt></a> has been deprecated by <span class="target" id="index-21"></span><a class="pep reference external" href="http://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#Py_UNICODE" title="Py_UNICODE"><tt class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></tt></a> and
<a class="reference internal" href="../c-api/unicode.html#Py_UNICODE" title="Py_UNICODE"><tt class="xref c c-type docutils literal"><span class="pre">Py_UNICODE*</span></tt></a> types:</p>
<blockquote>
<div><ul class="simple">
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_FromUnicode" title="PyUnicode_FromUnicode"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_FromUnicode</span></tt></a>: use <a class="reference internal" href="../c-api/unicode.html#PyUnicode_FromWideChar" title="PyUnicode_FromWideChar"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_FromWideChar()</span></tt></a> or
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_FromKindAndData" title="PyUnicode_FromKindAndData"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_FromKindAndData()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_AS_UNICODE" title="PyUnicode_AS_UNICODE"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_AS_UNICODE</span></tt></a>, <a class="reference internal" href="../c-api/unicode.html#PyUnicode_AsUnicode" title="PyUnicode_AsUnicode"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsUnicode()</span></tt></a>,
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_AsUnicodeAndSize" title="PyUnicode_AsUnicodeAndSize"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsUnicodeAndSize()</span></tt></a>: use <a class="reference internal" href="../c-api/unicode.html#PyUnicode_AsWideCharString" title="PyUnicode_AsWideCharString"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsWideCharString()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_AS_DATA" title="PyUnicode_AS_DATA"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_AS_DATA</span></tt></a>: use <a class="reference internal" href="../c-api/unicode.html#PyUnicode_DATA" title="PyUnicode_DATA"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_DATA</span></tt></a> with
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_READ" title="PyUnicode_READ"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_READ</span></tt></a> and <a class="reference internal" href="../c-api/unicode.html#PyUnicode_WRITE" title="PyUnicode_WRITE"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_WRITE</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_GET_SIZE" title="PyUnicode_GET_SIZE"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_GET_SIZE</span></tt></a>, <a class="reference internal" href="../c-api/unicode.html#PyUnicode_GetSize" title="PyUnicode_GetSize"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_GetSize()</span></tt></a>: use
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_GET_LENGTH" title="PyUnicode_GET_LENGTH"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_GET_LENGTH</span></tt></a> or <a class="reference internal" href="../c-api/unicode.html#PyUnicode_GetLength" title="PyUnicode_GetLength"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_GetLength()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_GET_DATA_SIZE" title="PyUnicode_GET_DATA_SIZE"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_GET_DATA_SIZE</span></tt></a>: use
<tt class="docutils literal"><span class="pre">PyUnicode_GET_LENGTH(str)</span> <span class="pre">*</span> <span class="pre">PyUnicode_KIND(str)</span></tt> (only work on ready
strings)</li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_AsUnicodeCopy" title="PyUnicode_AsUnicodeCopy"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsUnicodeCopy()</span></tt></a>: use <a class="reference internal" href="../c-api/unicode.html#PyUnicode_AsUCS4Copy" title="PyUnicode_AsUCS4Copy"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsUCS4Copy()</span></tt></a> or
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_AsWideCharString" title="PyUnicode_AsWideCharString"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsWideCharString()</span></tt></a></li>
<li><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_GetMax()</span></tt></li>
</ul>
</div></blockquote>
<p>Functions and macros manipulating Py_UNICODE* strings:</p>
<blockquote>
<div><ul class="simple">
<li><tt class="xref c c-macro docutils literal"><span class="pre">Py_UNICODE_strlen</span></tt>: use <a class="reference internal" href="../c-api/unicode.html#PyUnicode_GetLength" title="PyUnicode_GetLength"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_GetLength()</span></tt></a> or
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_GET_LENGTH" title="PyUnicode_GET_LENGTH"><tt class="xref c c-macro docutils literal"><span class="pre">PyUnicode_GET_LENGTH</span></tt></a></li>
<li><tt class="xref c c-macro docutils literal"><span class="pre">Py_UNICODE_strcat</span></tt>: use <a class="reference internal" href="../c-api/unicode.html#PyUnicode_CopyCharacters" title="PyUnicode_CopyCharacters"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_CopyCharacters()</span></tt></a> or
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_FromFormat" title="PyUnicode_FromFormat"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_FromFormat()</span></tt></a></li>
<li><tt class="xref c c-macro docutils literal"><span class="pre">Py_UNICODE_strcpy</span></tt>, <tt class="xref c c-macro docutils literal"><span class="pre">Py_UNICODE_strncpy</span></tt>,
<tt class="xref c c-macro docutils literal"><span class="pre">Py_UNICODE_COPY</span></tt>: use <a class="reference internal" href="../c-api/unicode.html#PyUnicode_CopyCharacters" title="PyUnicode_CopyCharacters"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_CopyCharacters()</span></tt></a> or
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_Substring" title="PyUnicode_Substring"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_Substring()</span></tt></a></li>
<li><tt class="xref c c-macro docutils literal"><span class="pre">Py_UNICODE_strcmp</span></tt>: use <a class="reference internal" href="../c-api/unicode.html#PyUnicode_Compare" title="PyUnicode_Compare"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_Compare()</span></tt></a></li>
<li><tt class="xref c c-macro docutils literal"><span class="pre">Py_UNICODE_strncmp</span></tt>: use <a class="reference internal" href="../c-api/unicode.html#PyUnicode_Tailmatch" title="PyUnicode_Tailmatch"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_Tailmatch()</span></tt></a></li>
<li><tt class="xref c c-macro docutils literal"><span class="pre">Py_UNICODE_strchr</span></tt>, <tt class="xref c c-macro docutils literal"><span class="pre">Py_UNICODE_strrchr</span></tt>: use
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_FindChar" title="PyUnicode_FindChar"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_FindChar()</span></tt></a></li>
<li><tt class="xref c c-macro docutils literal"><span class="pre">Py_UNICODE_FILL</span></tt>: use <a class="reference internal" href="../c-api/unicode.html#PyUnicode_Fill" title="PyUnicode_Fill"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_Fill()</span></tt></a></li>
<li><tt class="xref c c-macro docutils literal"><span class="pre">Py_UNICODE_MATCH</span></tt></li>
</ul>
</div></blockquote>
<p>Encoders:</p>
<blockquote>
<div><ul class="simple">
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_Encode" title="PyUnicode_Encode"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_Encode()</span></tt></a>: use <tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsEncodedObject()</span></tt></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_EncodeUTF7" title="PyUnicode_EncodeUTF7"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_EncodeUTF7()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_EncodeUTF8" title="PyUnicode_EncodeUTF8"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_EncodeUTF8()</span></tt></a>: use <a class="reference internal" href="../c-api/unicode.html#PyUnicode_AsUTF8" title="PyUnicode_AsUTF8"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsUTF8()</span></tt></a> or
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_AsUTF8String" title="PyUnicode_AsUTF8String"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsUTF8String()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_EncodeUTF32" title="PyUnicode_EncodeUTF32"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_EncodeUTF32()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_EncodeUTF16" title="PyUnicode_EncodeUTF16"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_EncodeUTF16()</span></tt></a></li>
<li><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_EncodeUnicodeEscape:()</span></tt> use
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_AsUnicodeEscapeString" title="PyUnicode_AsUnicodeEscapeString"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsUnicodeEscapeString()</span></tt></a></li>
<li><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_EncodeRawUnicodeEscape:()</span></tt> use
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_AsRawUnicodeEscapeString" title="PyUnicode_AsRawUnicodeEscapeString"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsRawUnicodeEscapeString()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_EncodeLatin1" title="PyUnicode_EncodeLatin1"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_EncodeLatin1()</span></tt></a>: use <a class="reference internal" href="../c-api/unicode.html#PyUnicode_AsLatin1String" title="PyUnicode_AsLatin1String"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsLatin1String()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_EncodeASCII" title="PyUnicode_EncodeASCII"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_EncodeASCII()</span></tt></a>: use <a class="reference internal" href="../c-api/unicode.html#PyUnicode_AsASCIIString" title="PyUnicode_AsASCIIString"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsASCIIString()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_EncodeCharmap" title="PyUnicode_EncodeCharmap"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_EncodeCharmap()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_TranslateCharmap" title="PyUnicode_TranslateCharmap"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_TranslateCharmap()</span></tt></a></li>
<li><a class="reference internal" href="../c-api/unicode.html#PyUnicode_EncodeMBCS" title="PyUnicode_EncodeMBCS"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_EncodeMBCS()</span></tt></a>: use <a class="reference internal" href="../c-api/unicode.html#PyUnicode_AsMBCSString" title="PyUnicode_AsMBCSString"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_AsMBCSString()</span></tt></a> or
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_EncodeCodePage" title="PyUnicode_EncodeCodePage"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_EncodeCodePage()</span></tt></a> (with <tt class="docutils literal"><span class="pre">CP_ACP</span></tt> code_page)</li>
<li><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_EncodeDecimal()</span></tt>,
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_TransformDecimalToASCII" title="PyUnicode_TransformDecimalToASCII"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_TransformDecimalToASCII()</span></tt></a></li>
</ul>
</div></blockquote>
</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."><tt class="xref py py-mod docutils literal"><span class="pre">array</span></tt></a> module&#8217;s <tt class="docutils literal"><span class="pre">'u'</span></tt> 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#Py_UNICODE" title="Py_UNICODE"><tt class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></tt></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>Hash randomization is enabled by default. Set the <span class="target" id="index-22"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONHASHSEED"><tt class="xref std std-envvar docutils literal"><span class="pre">PYTHONHASHSEED</span></tt></a>
environment variable to <tt class="docutils literal"><span class="pre">0</span></tt> to disable hash randomization. See also the
<a class="reference internal" href="../reference/datamodel.html#object.__hash__" title="object.__hash__"><tt class="xref py py-meth docutils literal"><span class="pre">object.__hash__()</span></tt></a> method.</li>
<li><a class="reference external" href="http://bugs.python.org/issue12326">issue 12326</a>: On Linux, sys.platform doesn&#8217;t contain the major version
anymore. It is now always &#8216;linux&#8217;, instead of &#8216;linux2&#8217; or &#8216;linux3&#8217; depending
on the Linux version used to build Python. Replace sys.platform == &#8216;linux2&#8217;
with sys.platform.startswith(&#8216;linux&#8217;), or directly sys.platform == &#8216;linux&#8217; if
you don&#8217;t need to support older Python versions.</li>
<li><a class="reference external" href="http://bugs.python.org/issue13847">issue 13847</a>, <a class="reference external" href="http://bugs.python.org/issue14180">issue 14180</a>: <a class="reference internal" href="../library/time.html#module-time" title="time: Time access and conversions."><tt class="xref py py-mod docutils literal"><span class="pre">time</span></tt></a> and <a class="reference internal" href="../library/datetime.html#module-datetime" title="datetime: Basic date and time types."><tt class="xref py py-mod docutils literal"><span class="pre">datetime</span></tt></a>:
<a class="reference internal" href="../library/exceptions.html#OverflowError" title="OverflowError"><tt class="xref py py-exc docutils literal"><span class="pre">OverflowError</span></tt></a> is now raised instead of <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> if a
timestamp is out of range. <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is now raised if C functions
<tt class="xref c c-func docutils literal"><span class="pre">gmtime()</span></tt> or <tt class="xref c c-func docutils literal"><span class="pre">localtime()</span></tt> failed.</li>
<li>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"><tt class="xref py py-func docutils literal"><span class="pre">importlib.invalidate_caches()</span></tt></a> to clear
out the cache for the finders to notice the new file.</li>
<li><a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><tt class="xref py py-exc docutils literal"><span class="pre">ImportError</span></tt></a> now uses the full name of the module that was attemped to
be imported. Doctests that check ImportErrors&#8217; message will need to be
updated to use the full name of the module instead of just the tail of the
name.</li>
<li>The <strong>index</strong> argument to <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><tt class="xref py py-func docutils literal"><span class="pre">__import__()</span></tt></a> now defaults to 0 instead of -1
and no longer support negative values. It was an oversight when <span class="target" id="index-23"></span><a class="pep reference external" href="http://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"><tt class="xref py py-func docutils literal"><span class="pre">importlib.import_module()</span></tt></a> rather than call <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><tt class="xref py py-func docutils literal"><span class="pre">__import__()</span></tt></a> directly.</li>
<li><a class="reference internal" href="../library/functions.html#__import__" title="__import__"><tt class="xref py py-func docutils literal"><span class="pre">__import__()</span></tt></a> no longer allows one to use an index value other than 0
for top-level modules. E.g. <tt class="docutils literal"><span class="pre">__import__('sys',</span> <span class="pre">level=1)</span></tt> is now an error.</li>
<li>Because <a class="reference internal" href="../library/sys.html#sys.meta_path" title="sys.meta_path"><tt class="xref py py-attr docutils literal"><span class="pre">sys.meta_path</span></tt></a> and <a class="reference internal" href="../library/sys.html#sys.path_hooks" title="sys.path_hooks"><tt class="xref py py-attr docutils literal"><span class="pre">sys.path_hooks</span></tt></a> now have finders on
them by default, you will most likely want to use <tt class="xref py py-meth docutils literal"><span class="pre">list.insert()</span></tt> instead
of <tt class="xref py py-meth docutils literal"><span class="pre">list.append()</span></tt> to add to those lists.</li>
<li>Because <tt class="xref docutils literal"><span class="pre">None</span></tt> is now inserted into <a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><tt class="xref py py-attr docutils literal"><span class="pre">sys.path_importer_cache</span></tt></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 <tt class="xref docutils literal"><span class="pre">None</span></tt> <strong>and</strong>
<a class="reference internal" href="../library/imp.html#imp.NullImporter" title="imp.NullImporter"><tt class="xref py py-class docutils literal"><span class="pre">imp.NullImporter</span></tt></a> to be backwards-compatible. This will lead to extra
overhead on older versions of Python that re-insert <tt class="xref docutils literal"><span class="pre">None</span></tt> into
<a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><tt class="xref py py-attr docutils literal"><span class="pre">sys.path_importer_cache</span></tt></a> where it repesents the use of implicit
finders, but semantically it should not change anything.</li>
<li><a class="reference internal" href="../library/importlib.html#importlib.abc.SourceLoader.path_mtime" title="importlib.abc.SourceLoader.path_mtime"><tt class="xref py py-meth docutils literal"><span class="pre">importlib.abc.SourceLoader.path_mtime()</span></tt></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"><tt class="xref py py-meth docutils literal"><span class="pre">importlib.abc.SourceLoader.path_stats()</span></tt></a> as bytecode files now store
both the modification time and size of the source file the bytecode file was
compiled from.</li>
<li><a class="reference internal" href="../library/importlib.html#importlib.abc.Finder" title="importlib.abc.Finder"><tt class="xref py py-class docutils literal"><span class="pre">importlib.abc.Finder</span></tt></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&#8217;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"><em class="xref std std-term">path entry finders</em></a>.</li>
<li><a class="reference internal" href="../library/pkgutil.html#module-pkgutil" title="pkgutil: Utilities for the import system."><tt class="xref py py-mod docutils literal"><span class="pre">pkgutil</span></tt></a> has been converted to use <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: An implementation of the import machinery."><tt class="xref py py-mod docutils literal"><span class="pre">importlib</span></tt></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"><tt class="xref py py-func docutils literal"><span class="pre">pkgutil.iter_importers()</span></tt></a> and <a class="reference internal" href="../library/pkgutil.html#pkgutil.walk_packages" title="pkgutil.walk_packages"><tt class="xref py py-func docutils literal"><span class="pre">pkgutil.walk_packages()</span></tt></a> functions
special case the standard import hooks so they are still supported even
though they do not provide the non-standard <tt class="docutils literal"><span class="pre">iter_modules()</span></tt> method.</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 class="first">In the course of changes to the buffer API the undocumented
<tt class="xref c c-member docutils literal"><span class="pre">smalltable</span></tt> member of the
<a class="reference internal" href="../c-api/buffer.html#Py_buffer" title="Py_buffer"><tt class="xref c c-type docutils literal"><span class="pre">Py_buffer</span></tt></a> structure has been removed and the
layout of the <tt class="xref c c-type docutils literal"><span class="pre">PyMemoryViewObject</span></tt> has changed.</p>
<p>All extensions relying on the relevant parts in <tt class="docutils literal"><span class="pre">memoryobject.h</span></tt>
or <tt class="docutils literal"><span class="pre">object.h</span></tt> must be rebuilt.</p>
</li>
<li><p class="first">Due to <a class="reference internal" href="#pep-393"><em>PEP 393</em></a>, the <a class="reference internal" href="../c-api/unicode.html#Py_UNICODE" title="Py_UNICODE"><tt class="xref c c-type docutils literal"><span class="pre">Py_UNICODE</span></tt></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"><em>Unicode API</em></a>.</p>
<p>However, if you only have been using high-level functions such as
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_Concat" title="PyUnicode_Concat"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_Concat()</span></tt></a>, <a class="reference internal" href="../c-api/unicode.html#PyUnicode_Join" title="PyUnicode_Join"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_Join()</span></tt></a> or
<a class="reference internal" href="../c-api/unicode.html#PyUnicode_FromFormat" title="PyUnicode_FromFormat"><tt class="xref c c-func docutils literal"><span class="pre">PyUnicode_FromFormat()</span></tt></a>, your code will automatically take
advantage of the new unicode representations.</p>
</li>
<li><p class="first"><a class="reference internal" href="../c-api/import.html#PyImport_GetMagicNumber" title="PyImport_GetMagicNumber"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_GetMagicNumber()</span></tt></a> now returns -1 upon failure.</p>
</li>
<li><p class="first">As a negative value for the <strong>level</strong> argument to <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><tt class="xref py py-func docutils literal"><span class="pre">__import__()</span></tt></a> is no
longer valid, the same now holds for <a class="reference internal" href="../c-api/import.html#PyImport_ImportModuleLevel" title="PyImport_ImportModuleLevel"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModuleLevel()</span></tt></a>.
This also means that the value of <strong>level</strong> used by
<a class="reference internal" href="../c-api/import.html#PyImport_ImportModuleEx" title="PyImport_ImportModuleEx"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModuleEx()</span></tt></a> is now 0 instead of -1.</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 class="first">The range of possible file names for C extensions has been narrowed.
Very rarely used spellings have been suppressed: under POSIX, files
named <tt class="docutils literal"><span class="pre">xxxmodule.so</span></tt>, <tt class="docutils literal"><span class="pre">xxxmodule.abi3.so</span></tt> and
<tt class="docutils literal"><span class="pre">xxxmodule.cpython-*.so</span></tt> are no longer recognized as implementing
the <tt class="docutils literal"><span class="pre">xxx</span></tt> module.  If you had been generating such files, you have
to switch to the other spellings (i.e., remove the <tt class="docutils literal"><span class="pre">module</span></tt> string
from the file names).</p>
<p>(implemented in <a class="reference external" href="http://bugs.python.org/issue14040">issue 14040</a>.)</p>
</li>
</ul>
</div>
<div class="section" id="other-issues">
<h3>Other issues<a class="headerlink" href="#other-issues" title="Permalink to this headline">¶</a></h3>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">What&#8217;s New In Python 3.3</a><ul>
<li><a class="reference internal" href="#summary-release-highlights">Summary &#8211; 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-namespace-packages">PEP 420: 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-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="#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="#new-email-package-features">New Email Package Features</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>
</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-binascii">base64, 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="#ftplib">ftplib</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="#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="#math">math</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="#shutil">shutil</a></li>
<li><a class="reference internal" href="#signal">signal</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="#ssl">ssl</a></li>
<li><a class="reference internal" href="#stat">stat</a></li>
<li><a class="reference internal" href="#sys">sys</a></li>
<li><a class="reference internal" href="#textwrap">textwrap</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="#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>
</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="#other-issues">Other issues</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="index.html"
                        title="previous chapter">What&#8217;s New in Python</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="3.2.html"
                        title="next chapter">What&#8217;s New In Python 3.2</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/whatsnew/3.3.txt"
         rel="nofollow">Show Source</a></li>
</ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <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="index.html" title="What’s New in Python"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="http://www.python.org/">Python</a> &raquo;</li>
        <li><a href="../index.html">3.3.0 Documentation</a> &raquo;</li>

          <li><a href="index.html" >What&#8217;s New in Python</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2012, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.  
    <a href="http://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Sep 29, 2012.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>

  </body>
</html>