summaryrefslogtreecommitdiff
path: root/Doc/library
diff options
context:
space:
mode:
authorZachary Ware <zachary.ware@gmail.com>2014-07-07 14:35:02 -0500
committerZachary Ware <zachary.ware@gmail.com>2014-07-07 14:35:02 -0500
commite55c07614b4f6d4961a2d3fc9af4cf92c2b2615c (patch)
tree6eabbaa47b0066ea2480864b78e69c645daed3da /Doc/library
parentbb715c3208e98a5abf245de2fcfd7e93e28614e0 (diff)
parent8eb1f397f7637f49e102198ef49e156e229b09de (diff)
downloadcpython-e55c07614b4f6d4961a2d3fc9af4cf92c2b2615c.tar.gz
Issue #17846: Merge with 3.4
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/argparse.rst2
-rw-r--r--Doc/library/asynchat.rst34
-rw-r--r--Doc/library/cmd.rst2
-rw-r--r--Doc/library/code.rst2
-rw-r--r--Doc/library/codecs.rst12
-rw-r--r--Doc/library/collections.abc.rst2
-rw-r--r--Doc/library/collections.rst5
-rw-r--r--Doc/library/concurrent.futures.rst2
-rw-r--r--Doc/library/configparser.rst6
-rw-r--r--Doc/library/copyreg.rst2
-rw-r--r--Doc/library/csv.rst1
-rw-r--r--Doc/library/datetime.rst11
-rw-r--r--Doc/library/dbm.rst9
-rw-r--r--Doc/library/decimal.rst15
-rw-r--r--Doc/library/difflib.rst16
-rw-r--r--Doc/library/dis.rst10
-rw-r--r--Doc/library/doctest.rst12
-rw-r--r--Doc/library/formatter.rst2
-rw-r--r--Doc/library/heapq.rst14
-rw-r--r--Doc/library/http.server.rst2
-rw-r--r--Doc/library/imghdr.rst10
-rw-r--r--Doc/library/importlib.rst58
-rw-r--r--Doc/library/inspect.rst36
-rw-r--r--Doc/library/io.rst31
-rw-r--r--Doc/library/ipaddress.rst36
-rw-r--r--Doc/library/itertools.rst18
-rw-r--r--Doc/library/json.rst53
-rw-r--r--Doc/library/logging.handlers.rst2
-rw-r--r--Doc/library/multiprocessing.rst3
-rw-r--r--Doc/library/operator.rst18
-rw-r--r--Doc/library/os.rst39
-rw-r--r--Doc/library/pathlib.rst19
-rw-r--r--Doc/library/pkgutil.rst4
-rw-r--r--Doc/library/plistlib.rst2
-rw-r--r--Doc/library/random.rst3
-rw-r--r--Doc/library/resource.rst2
-rw-r--r--Doc/library/select.rst2
-rw-r--r--Doc/library/selectors.rst11
-rw-r--r--Doc/library/shutil.rst44
-rw-r--r--Doc/library/signal.rst10
-rw-r--r--Doc/library/site.rst20
-rw-r--r--Doc/library/smtpd.rst24
-rw-r--r--Doc/library/smtplib.rst39
-rw-r--r--Doc/library/socket.rst28
-rw-r--r--Doc/library/socketserver.rst4
-rw-r--r--Doc/library/ssl.rst55
-rw-r--r--Doc/library/stat.rst28
-rw-r--r--Doc/library/subprocess.rst1
-rw-r--r--Doc/library/tempfile.rst7
-rw-r--r--Doc/library/threading.rst2
-rw-r--r--Doc/library/tkinter.ttk.rst2
-rw-r--r--Doc/library/token.rst1
-rw-r--r--Doc/library/tracemalloc.rst2
-rw-r--r--Doc/library/turtle.rst6
-rw-r--r--Doc/library/types.rst4
-rw-r--r--Doc/library/unicodedata.rst8
-rw-r--r--Doc/library/unittest.mock.rst47
-rw-r--r--Doc/library/urllib.request.rst4
-rw-r--r--Doc/library/weakref.rst4
-rw-r--r--Doc/library/webbrowser.rst2
-rw-r--r--Doc/library/wsgiref.rst9
-rw-r--r--Doc/library/xml.dom.rst2
-rw-r--r--Doc/library/xmlrpc.client.rst23
63 files changed, 708 insertions, 176 deletions
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index b1b5135eac..36dc5f384b 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -1873,7 +1873,7 @@ Customizing file parsing
Arguments that are read from a file (see the *fromfile_prefix_chars*
keyword argument to the :class:`ArgumentParser` constructor) are read one
- argument per line. :meth:`convert_arg_line_to_args` can be overriden for
+ argument per line. :meth:`convert_arg_line_to_args` can be overridden for
fancier reading.
This method takes a single argument *arg_line* which is a string read from
diff --git a/Doc/library/asynchat.rst b/Doc/library/asynchat.rst
index c6fa06162e..794da8cced 100644
--- a/Doc/library/asynchat.rst
+++ b/Doc/library/asynchat.rst
@@ -147,40 +147,6 @@ connection requests.
by the channel after :meth:`found_terminator` is called.
-asynchat - Auxiliary Classes
-------------------------------------------
-
-.. class:: fifo(list=None)
-
- A :class:`fifo` holding data which has been pushed by the application but
- not yet popped for writing to the channel. A :class:`fifo` is a list used
- to hold data and/or producers until they are required. If the *list*
- argument is provided then it should contain producers or data items to be
- written to the channel.
-
-
- .. method:: is_empty()
-
- Returns ``True`` if and only if the fifo is empty.
-
-
- .. method:: first()
-
- Returns the least-recently :meth:`push`\ ed item from the fifo.
-
-
- .. method:: push(data)
-
- Adds the given data (which may be a string or a producer object) to the
- producer fifo.
-
-
- .. method:: pop()
-
- If the fifo is not empty, returns ``True, first()``, deleting the popped
- item. Returns ``False, None`` for an empty fifo.
-
-
.. _asynchat-example:
asynchat Example
diff --git a/Doc/library/cmd.rst b/Doc/library/cmd.rst
index 97229280c3..6d57b77ccf 100644
--- a/Doc/library/cmd.rst
+++ b/Doc/library/cmd.rst
@@ -252,7 +252,7 @@ immediate playback::
'Move turtle to an absolute position with changing orientation. GOTO 100 200'
goto(*parse(arg))
def do_home(self, arg):
- 'Return turtle to the home postion: HOME'
+ 'Return turtle to the home position: HOME'
home()
def do_circle(self, arg):
'Draw circle with given radius an options extent and steps: CIRCLE 50'
diff --git a/Doc/library/code.rst b/Doc/library/code.rst
index 5b5d7cc8c1..99bdedc065 100644
--- a/Doc/library/code.rst
+++ b/Doc/library/code.rst
@@ -4,6 +4,7 @@
.. module:: code
:synopsis: Facilities to implement read-eval-print loops.
+**Source code:** :source:`Lib/code.py`
The ``code`` module provides facilities to implement read-eval-print loops in
Python. Two classes and convenience functions are included which can be used to
@@ -165,4 +166,3 @@ interpreter objects as well as the following additions.
newline. When the user enters the EOF key sequence, :exc:`EOFError` is raised.
The base implementation reads from ``sys.stdin``; a subclass may replace this
with a different implementation.
-
diff --git a/Doc/library/codecs.rst b/Doc/library/codecs.rst
index fb3af3bf37..36144e9ef2 100644
--- a/Doc/library/codecs.rst
+++ b/Doc/library/codecs.rst
@@ -7,6 +7,7 @@
.. sectionauthor:: Marc-André Lemburg <mal@lemburg.com>
.. sectionauthor:: Martin v. Löwis <martin@v.loewis.de>
+**Source code:** :source:`Lib/codecs.py`
.. index::
single: Unicode
@@ -22,10 +23,9 @@ manages the codec and error handling lookup process.
It defines the following functions:
-.. function:: encode(obj, [encoding[, errors]])
+.. function:: encode(obj, encoding='utf-8', errors='strict')
- Encodes *obj* using the codec registered for *encoding*. The default
- encoding is ``utf-8``.
+ Encodes *obj* using the codec registered for *encoding*.
*Errors* may be given to set the desired error handling scheme. The
default error handler is ``strict`` meaning that encoding errors raise
@@ -33,10 +33,9 @@ It defines the following functions:
:exc:`UnicodeEncodeError`). Refer to :ref:`codec-base-classes` for more
information on codec error handling.
-.. function:: decode(obj, [encoding[, errors]])
+.. function:: decode(obj, encoding='utf-8', errors='strict')
- Decodes *obj* using the codec registered for *encoding*. The default
- encoding is ``utf-8``.
+ Decodes *obj* using the codec registered for *encoding*.
*Errors* may be given to set the desired error handling scheme. The
default error handler is ``strict`` meaning that decoding errors raise
@@ -1420,4 +1419,3 @@ This module implements a variant of the UTF-8 codec: On encoding a UTF-8 encoded
BOM will be prepended to the UTF-8 encoded bytes. For the stateful encoder this
is only done once (on the first write to the byte stream). For decoding an
optional UTF-8 encoded BOM at the start of the data will be skipped.
-
diff --git a/Doc/library/collections.abc.rst b/Doc/library/collections.abc.rst
index 0bb26f938f..5f7888a27d 100644
--- a/Doc/library/collections.abc.rst
+++ b/Doc/library/collections.abc.rst
@@ -179,7 +179,7 @@ Notes on using :class:`Set` and :class:`MutableSet` as a mixin:
(3)
The :class:`Set` mixin provides a :meth:`_hash` method to compute a hash value
for the set; however, :meth:`__hash__` is not defined because not all sets
- are hashable or immutable. To add set hashabilty using mixins,
+ are hashable or immutable. To add set hashability using mixins,
inherit from both :meth:`Set` and :meth:`Hashable`, then define
``__hash__ = Set._hash``.
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index f5fe12a739..3ec3240795 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -978,12 +978,15 @@ The :class:`OrderedDict` constructor and :meth:`update` method both accept
keyword arguments, but their order is lost because Python's function call
semantics pass-in keyword arguments using a regular unordered dictionary.
+.. versionchanged:: 3.5
+ The items, keys, and values :term:`views <view>` of :class:`OrderedDict` now
+ support reverse iteration using :func:`reversed`.
:class:`OrderedDict` Examples and Recipes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Since an ordered dictionary remembers its insertion order, it can be used
-in conjuction with sorting to make a sorted dictionary::
+in conjunction with sorting to make a sorted dictionary::
>>> # regular unsorted dictionary
>>> d = {'banana': 3, 'apple':4, 'pear': 1, 'orange': 2}
diff --git a/Doc/library/concurrent.futures.rst b/Doc/library/concurrent.futures.rst
index 0495737e8b..08c926a6d4 100644
--- a/Doc/library/concurrent.futures.rst
+++ b/Doc/library/concurrent.futures.rst
@@ -175,6 +175,8 @@ to a :class:`ProcessPoolExecutor` will result in deadlock.
An :class:`Executor` subclass that executes calls asynchronously using a pool
of at most *max_workers* processes. If *max_workers* is ``None`` or not
given, it will default to the number of processors on the machine.
+ If *max_workers* is lower or equal to ``0``, then a :exc:`ValueError`
+ will be raised.
.. versionchanged:: 3.3
When one of the worker processes terminates abruptly, a
diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst
index 024d27cb84..4d65a821d7 100644
--- a/Doc/library/configparser.rst
+++ b/Doc/library/configparser.rst
@@ -11,6 +11,8 @@
.. sectionauthor:: Christopher G. Petrilli <petrilli@amber.org>
.. sectionauthor:: Łukasz Langa <lukasz@langa.pl>
+**Source code:** :source:`Lib/configparser.py`
+
.. index::
pair: .ini; file
pair: configuration; file
@@ -386,7 +388,7 @@ However, there are a few differences that should be taken into account:
* All sections include ``DEFAULTSECT`` values as well which means that
``.clear()`` on a section may not leave the section visibly empty. This is
because default values cannot be deleted from the section (because technically
- they are not there). If they are overriden in the section, deleting causes
+ they are not there). If they are overridden in the section, deleting causes
the default value to be visible again. Trying to delete a default value
causes a ``KeyError``.
@@ -667,7 +669,7 @@ the :meth:`__init__` options:
More advanced customization may be achieved by overriding default values of
these parser attributes. The defaults are defined on the classes, so they
-may be overriden by subclasses or by attribute assignment.
+may be overridden by subclasses or by attribute assignment.
.. attribute:: BOOLEAN_STATES
diff --git a/Doc/library/copyreg.rst b/Doc/library/copyreg.rst
index 50d5879ae5..18306c7f99 100644
--- a/Doc/library/copyreg.rst
+++ b/Doc/library/copyreg.rst
@@ -9,7 +9,7 @@
module: pickle
module: copy
-The :mod:`copyreg` module offers a way to define fuctions used while pickling
+The :mod:`copyreg` module offers a way to define functions used while pickling
specific objects. The :mod:`pickle` and :mod:`copy` modules use those functions
when pickling/copying those objects. The module provides configuration
information about object constructors which are not classes.
diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst
index ccc9dc6e4c..616df55ed0 100644
--- a/Doc/library/csv.rst
+++ b/Doc/library/csv.rst
@@ -5,6 +5,7 @@
:synopsis: Write and read tabular data to and from delimited files.
.. sectionauthor:: Skip Montanaro <skip@pobox.com>
+**Source code:** :source:`Lib/csv.py`
.. index::
single: csv
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index e1b9e108f6..a25d63ff00 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -7,6 +7,8 @@
.. sectionauthor:: Tim Peters <tim@zope.com>
.. sectionauthor:: A.M. Kuchling <amk@amk.ca>
+**Source code:** :source:`Lib/datetime.py`
+
.. XXX what order should the types be discussed in?
The :mod:`datetime` module supplies classes for manipulating dates and times in
@@ -1376,10 +1378,13 @@ Supported operations:
* efficient pickling
-* in Boolean contexts, a :class:`.time` object is considered to be true if and
- only if, after converting it to minutes and subtracting :meth:`utcoffset` (or
- ``0`` if that's ``None``), the result is non-zero.
+In boolean contexts, a :class:`.time` object is always considered to be true.
+.. versionchanged:: 3.5
+ Before Python 3.5, a :class:`.time` object was considered to be false if it
+ represented midnight in UTC. This behavior was considered obscure and
+ error-prone and has been removed in Python 3.5. See :issue:`13936` for full
+ details.
Instance methods:
diff --git a/Doc/library/dbm.rst b/Doc/library/dbm.rst
index e6a82d67ce..3f3c43d438 100644
--- a/Doc/library/dbm.rst
+++ b/Doc/library/dbm.rst
@@ -325,13 +325,18 @@ The module defines the following:
dumbdbm database is created, files with :file:`.dat` and :file:`.dir` extensions
are created.
- The optional *flag* argument is currently ignored; the database is always opened
- for update, and will be created if it does not exist.
+ The optional *flag* argument supports only the semantics of ``'c'``
+ and ``'n'`` values. Other values will default to database being always
+ opened for update, and will be created if it does not exist.
The optional *mode* argument is the Unix mode of the file, used only when the
database has to be created. It defaults to octal ``0o666`` (and will be modified
by the prevailing umask).
+ .. versionchanged:: 3.5
+ :func:`.open` always creates a new database when the flag has the value
+ ``'n'``.
+
In addition to the methods provided by the
:class:`collections.abc.MutableMapping` class, :class:`dumbdbm` objects
provide the following methods:
diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst
index 059ae7cb16..705298536b 100644
--- a/Doc/library/decimal.rst
+++ b/Doc/library/decimal.rst
@@ -12,6 +12,8 @@
.. moduleauthor:: Stefan Krah <skrah at bytereef.org>
.. sectionauthor:: Raymond D. Hettinger <python at rcn.com>
+**Source code:** :source:`Lib/decimal.py`
+
.. import modules for testing inline doctests with the Sphinx doctest builder
.. testsetup:: *
@@ -742,7 +744,7 @@ Decimal objects
* ``"NaN"``, indicating that the operand is a quiet NaN (Not a Number).
* ``"sNaN"``, indicating that the operand is a signaling NaN.
- .. method:: quantize(exp, rounding=None, context=None, watchexp=True)
+ .. method:: quantize(exp, rounding=None, context=None)
Return a value equal to the first operand after rounding and having the
exponent of the second operand.
@@ -765,14 +767,8 @@ Decimal objects
``context`` argument; if neither argument is given the rounding mode of
the current thread's context is used.
- If *watchexp* is set (default), then an error is returned whenever the
- resulting exponent is greater than :attr:`Emax` or less than
- :attr:`Etiny`.
-
- .. deprecated:: 3.3
- *watchexp* is an implementation detail from the pure Python version
- and is not present in the C version. It will be removed in version
- 3.4, where it defaults to ``True``.
+ An error is returned whenever the resulting exponent is greater than
+ :attr:`Emax` or less than :attr:`Etiny`.
.. method:: radix()
@@ -2092,4 +2088,3 @@ Alternatively, inputs can be rounded upon creation using the
>>> Context(prec=5, rounding=ROUND_DOWN).create_decimal('1.2345678')
Decimal('1.2345')
-
diff --git a/Doc/library/difflib.rst b/Doc/library/difflib.rst
index 2a75d2cb15..707f179baa 100644
--- a/Doc/library/difflib.rst
+++ b/Doc/library/difflib.rst
@@ -7,6 +7,8 @@
.. sectionauthor:: Tim Peters <tim_one@users.sourceforge.net>
.. Markup by Fred L. Drake, Jr. <fdrake@acm.org>
+**Source code:** :source:`Lib/difflib.py`
+
.. testsetup::
import sys
@@ -25,7 +27,9 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module.
little fancier than, an algorithm published in the late 1980's by Ratcliff and
Obershelp under the hyperbolic name "gestalt pattern matching." The idea is to
find the longest contiguous matching subsequence that contains no "junk"
- elements (the Ratcliff and Obershelp algorithm doesn't address junk). The same
+ elements; these "junk" elements are ones that are uninteresting in some
+ sense, such as blank lines or whitespace. (Handling junk is an
+ extension to the Ratcliff and Obershelp algorithm.) The same
idea is then applied recursively to the pieces of the sequences to the left and
to the right of the matching subsequence. This does not yield minimal edit
sequences, but does tend to yield matches that "look right" to people.
@@ -208,7 +212,7 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module.
Compare *a* and *b* (lists of strings); return a :class:`Differ`\ -style
delta (a :term:`generator` generating the delta lines).
- Optional keyword parameters *linejunk* and *charjunk* are for filter functions
+ Optional keyword parameters *linejunk* and *charjunk* are filtering functions
(or ``None``):
*linejunk*: A function that accepts a single string argument, and returns
@@ -222,7 +226,7 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module.
*charjunk*: A function that accepts a character (a string of length 1), and
returns if the character is junk, or false if not. The default is module-level
function :func:`IS_CHARACTER_JUNK`, which filters out whitespace characters (a
- blank or tab; note: bad idea to include newline in this!).
+ blank or tab; it's a bad idea to include newline in this!).
:file:`Tools/scripts/ndiff.py` is a command-line front-end to this function.
@@ -622,6 +626,12 @@ The :class:`Differ` class has this constructor:
length 1), and returns true if the character is junk. The default is ``None``,
meaning that no character is considered junk.
+ These junk-filtering functions speed up matching to find
+ differences and do not cause any differing lines or characters to
+ be ignored. Read the description of the
+ :meth:`~SequenceMatcher.find_longest_match` method's *isjunk*
+ parameter for an explanation.
+
:class:`Differ` objects are used (deltas generated) via a single method:
diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index d86550f182..fbabe35772 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -364,6 +364,11 @@ result back on the stack.
Implements ``TOS = TOS1 * TOS``.
+.. opcode:: BINARY_MATRIX_MULTIPLY
+
+ Implements ``TOS = TOS1 @ TOS``.
+
+
.. opcode:: BINARY_FLOOR_DIVIDE
Implements ``TOS = TOS1 // TOS``.
@@ -436,6 +441,11 @@ the original TOS1.
Implements in-place ``TOS = TOS1 * TOS``.
+.. opcode:: INPLACE_MATRIX_MULTIPLY
+
+ Implements in-place ``TOS = TOS1 @ TOS``.
+
+
.. opcode:: INPLACE_FLOOR_DIVIDE
Implements in-place ``TOS = TOS1 // TOS``.
diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst
index 50626e9b0c..fb63fde3e4 100644
--- a/Doc/library/doctest.rst
+++ b/Doc/library/doctest.rst
@@ -1058,15 +1058,9 @@ from text files and modules with doctests:
This function uses the same search technique as :func:`testmod`.
- .. note::
- Unlike :func:`testmod` and :class:`DocTestFinder`, this function raises
- a :exc:`ValueError` if *module* contains no docstrings. You can prevent
- this error by passing a :class:`DocTestFinder` instance as the
- *test_finder* argument with its *exclude_empty* keyword argument set
- to ``False``::
-
- >>> finder = doctest.DocTestFinder(exclude_empty=False)
- >>> suite = doctest.DocTestSuite(test_finder=finder)
+ .. versionchanged:: 3.5
+ :func:`DocTestSuite` returns an empty :class:`unittest.TestSuite` if *module*
+ contains no docstrings instead of raising :exc:`ValueError`.
Under the covers, :func:`DocTestSuite` creates a :class:`unittest.TestSuite` out
diff --git a/Doc/library/formatter.rst b/Doc/library/formatter.rst
index 1847a8094b..a515f74f64 100644
--- a/Doc/library/formatter.rst
+++ b/Doc/library/formatter.rst
@@ -5,7 +5,7 @@
:synopsis: Generic output formatter and device interface.
:deprecated:
-.. deprecated:: 3.4
+.. deprecated-removed:: 3.4 3.6
Due to lack of usage, the formatter module has been deprecated and is slated
for removal in Python 3.6.
diff --git a/Doc/library/heapq.rst b/Doc/library/heapq.rst
index 4f1a682a87..2a41434094 100644
--- a/Doc/library/heapq.rst
+++ b/Doc/library/heapq.rst
@@ -81,7 +81,7 @@ The following functions are provided:
The module also offers three general purpose functions based on heaps.
-.. function:: merge(*iterables)
+.. function:: merge(*iterables, key=None, reverse=False)
Merge multiple sorted inputs into a single sorted output (for example, merge
timestamped entries from multiple log files). Returns an :term:`iterator`
@@ -91,6 +91,18 @@ The module also offers three general purpose functions based on heaps.
not pull the data into memory all at once, and assumes that each of the input
streams is already sorted (smallest to largest).
+ Has two optional arguments which must be specified as keyword arguments.
+
+ *key* specifies a :term:`key function` of one argument that is used to
+ extract a comparison key from each input element. The default value is
+ ``None`` (compare the elements directly).
+
+ *reverse* is a boolean value. If set to ``True``, then the input elements
+ are merged as if each comparison were reversed.
+
+ .. versionchanged:: 3.5
+ Added the optional *key* and *reverse* parameters.
+
.. function:: nlargest(n, iterable, key=None)
diff --git a/Doc/library/http.server.rst b/Doc/library/http.server.rst
index 0d8e7fe6c7..ec5464332e 100644
--- a/Doc/library/http.server.rst
+++ b/Doc/library/http.server.rst
@@ -220,7 +220,7 @@ of which this module provides three different variants:
.. method:: send_response_only(code, message=None)
- Sends the reponse header only, used for the purposes when ``100
+ Sends the response header only, used for the purposes when ``100
Continue`` response is sent by the server to the client. The headers not
buffered and sent directly the output stream.If the *message* is not
specified, the HTTP message corresponding the response *code* is sent.
diff --git a/Doc/library/imghdr.rst b/Doc/library/imghdr.rst
index 9e8952339c..c60df24c5a 100644
--- a/Doc/library/imghdr.rst
+++ b/Doc/library/imghdr.rst
@@ -48,6 +48,16 @@ from :func:`what`:
+------------+-----------------------------------+
| ``'png'`` | Portable Network Graphics |
+------------+-----------------------------------+
+| ``'webp'`` | WebP files |
++------------+-----------------------------------+
+| ``'exr'`` | OpenEXR Files |
++------------+-----------------------------------+
+
+.. versionadded:: 3.5
+ The *exr* format was added.
+
+.. versionchanged:: 3.5
+ The *webp* type was added.
You can extend the list of file types :mod:`imghdr` can recognize by appending
to this variable:
diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
index 09a5d710b5..0ca84909a1 100644
--- a/Doc/library/importlib.rst
+++ b/Doc/library/importlib.rst
@@ -499,7 +499,7 @@ ABC hierarchy::
.. versionchanged:: 3.4
Raises :exc:`ImportError` instead of :exc:`NotImplementedError`.
- .. method:: source_to_code(data, path='<string>')
+ .. staticmethod:: source_to_code(data, path='<string>')
Create a code object from Python source.
@@ -508,8 +508,14 @@ ABC hierarchy::
the "path" to where the source code originated from, which can be an
abstract concept (e.g. location in a zip file).
+ With the subsequent code object one can execute it in a module by
+ running ``exec(code, module.__dict__)``.
+
.. versionadded:: 3.4
+ .. versionchanged:: 3.5
+ Made the method static.
+
.. method:: exec_module(module)
Implementation of :meth:`Loader.exec_module`.
@@ -1123,6 +1129,21 @@ an :term:`importer`.
.. versionadded:: 3.4
+.. function:: module_from_spec(spec)
+
+ Create a new module based on **spec**.
+
+ If the module object is from ``spec.loader.create_module()``, then any
+ pre-existing attributes will not be reset. Also, no :exc:`AttributeError`
+ will be raised if triggered while accessing **spec** or setting an attribute
+ on the module.
+
+ This function is preferred over using :class:`types.ModuleType` to create a
+ new module as **spec** is used to set as many import-controlled attributes on
+ the module as possible.
+
+ .. versionadded:: 3.5
+
.. decorator:: module_for_loader
A :term:`decorator` for :meth:`importlib.abc.Loader.load_module`
@@ -1201,3 +1222,38 @@ an :term:`importer`.
module will be file-based.
.. versionadded:: 3.4
+
+.. class:: LazyLoader(loader)
+
+ A class which postpones the execution of the loader of a module until the
+ module has an attribute accessed.
+
+ This class **only** works with loaders that define
+ :meth:`importlib.abc.Loader.exec_module` as control over what module type
+ is used for the module is required. For the same reasons, the loader
+ **cannot** define :meth:`importlib.abc.Loader.create_module`. Finally,
+ modules which substitute the object placed into :attr:`sys.modules` will
+ not work as there is no way to properly replace the module references
+ throughout the interpreter safely; :exc:`ValueError` is raised if such a
+ substitution is detected.
+
+ .. note::
+ For projects where startup time is critical, this class allows for
+ potentially minimizing the cost of loading a module if it is never used.
+ For projects where startup time is not essential then use of this class is
+ **heavily** discouraged due to error messages created during loading being
+ postponed and thus occurring out of context.
+
+ .. versionadded:: 3.5
+
+ .. classmethod:: factory(loader)
+
+ A static method which returns a callable that creates a lazy loader. This
+ is meant to be used in situations where the loader is passed by class
+ instead of by instance.
+ ::
+
+ suffixes = importlib.machinery.SOURCE_SUFFIXES
+ loader = importlib.machinery.SourceFileLoader
+ lazy_loader = importlib.util.LazyLoader.factory(loader)
+ finder = importlib.machinery.FileFinder(path, [(lazy_loader, suffixes)])
diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst
index 0c087123e8..359f83374a 100644
--- a/Doc/library/inspect.rst
+++ b/Doc/library/inspect.rst
@@ -159,6 +159,16 @@ attributes:
| | | arguments and local |
| | | variables |
+-----------+-----------------+---------------------------+
+| generator | __name__ | name |
++-----------+-----------------+---------------------------+
+| | __qualname__ | qualified name |
++-----------+-----------------+---------------------------+
+| | gi_frame | frame |
++-----------+-----------------+---------------------------+
+| | gi_running | is the generator running? |
++-----------+-----------------+---------------------------+
+| | gi_code | code |
++-----------+-----------------+---------------------------+
| builtin | __doc__ | documentation string |
+-----------+-----------------+---------------------------+
| | __name__ | original name of this |
@@ -169,6 +179,12 @@ attributes:
| | | ``None`` |
+-----------+-----------------+---------------------------+
+.. versionchanged:: 3.5
+
+ Add ``__qualname__`` attribute to generators. The ``__name__`` attribute of
+ generators is now set from the function name, instead of the code name, and
+ it can now be modified.
+
.. function:: getmembers(object[, predicate])
@@ -462,6 +478,9 @@ function.
Signature objects are *immutable*. Use :meth:`Signature.replace` to make a
modified copy.
+ .. versionchanged:: 3.5
+ Signature objects are picklable and hashable.
+
.. attribute:: Signature.empty
A special class-level marker to specify absence of a return annotation.
@@ -506,12 +525,29 @@ function.
>>> str(new_sig)
"(a, b) -> 'new return anno'"
+ .. classmethod:: Signature.from_callable(obj)
+
+ Return a :class:`Signature` (or its subclass) object for a given callable
+ ``obj``. This method simplifies subclassing of :class:`Signature`:
+
+ ::
+
+ class MySignature(Signature):
+ pass
+ sig = MySignature.from_callable(min)
+ assert isinstance(sig, MySignature)
+
+ .. versionadded:: 3.5
+
.. class:: Parameter(name, kind, \*, default=Parameter.empty, annotation=Parameter.empty)
Parameter objects are *immutable*. Instead of modifying a Parameter object,
you can use :meth:`Parameter.replace` to create a modified copy.
+ .. versionchanged:: 3.5
+ Parameter objects are picklable and hashable.
+
.. attribute:: Parameter.empty
A special class-level marker to specify absence of default values and
diff --git a/Doc/library/io.rst b/Doc/library/io.rst
index 0c7d3c7f6b..03e3fd4437 100644
--- a/Doc/library/io.rst
+++ b/Doc/library/io.rst
@@ -391,8 +391,8 @@ I/O Base Classes
.. method:: readinto(b)
Read up to ``len(b)`` bytes into :class:`bytearray` *b* and return the
- number of bytes read. If the object is in non-blocking mode and no
- bytes are available, ``None`` is returned.
+ number of bytes read. If the object is in non-blocking mode and no bytes
+ are available, ``None`` is returned.
.. method:: write(b)
@@ -465,9 +465,10 @@ I/O Base Classes
.. method:: read1(size=-1)
- Read and return up to *size* bytes, with at most one call to the underlying
- raw stream's :meth:`~RawIOBase.read` method. This can be useful if you
- are implementing your own buffering on top of a :class:`BufferedIOBase`
+ Read and return up to *size* bytes, with at most one call to the
+ underlying raw stream's :meth:`~RawIOBase.read` (or
+ :meth:`~RawIOBase.readinto`) method. This can be useful if you are
+ implementing your own buffering on top of a :class:`BufferedIOBase`
object.
.. method:: readinto(b)
@@ -478,8 +479,19 @@ I/O Base Classes
Like :meth:`read`, multiple reads may be issued to the underlying raw
stream, unless the latter is interactive.
- A :exc:`BlockingIOError` is raised if the underlying raw stream is in
- non blocking-mode, and has no data available at the moment.
+ A :exc:`BlockingIOError` is raised if the underlying raw stream is in non
+ blocking-mode, and has no data available at the moment.
+
+ .. method:: readinto1(b)
+
+ Read up to ``len(b)`` bytes into bytearray *b*, ,using at most one call to
+ the underlying raw stream's :meth:`~RawIOBase.read` (or
+ :meth:`~RawIOBase.readinto`) method. Return the number of bytes read.
+
+ A :exc:`BlockingIOError` is raised if the underlying raw stream is in non
+ blocking-mode, and has no data available at the moment.
+
+ .. versionadded:: 3.5
.. method:: write(b)
@@ -596,6 +608,11 @@ than raw I/O does.
In :class:`BytesIO`, this is the same as :meth:`read`.
+ .. method:: readinto1()
+
+ In :class:`BytesIO`, this is the same as :meth:`readinto`.
+
+ .. versionadded:: 3.5
.. class:: BufferedReader(raw, buffer_size=DEFAULT_BUFFER_SIZE)
diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst
index 9625e71b04..d48fac95f4 100644
--- a/Doc/library/ipaddress.rst
+++ b/Doc/library/ipaddress.rst
@@ -103,7 +103,7 @@ write code that handles both IP versions correctly.
1. A string in decimal-dot notation, consisting of four decimal integers in
the inclusive range 0-255, separated by dots (e.g. ``192.168.0.1``). Each
integer represents an octet (byte) in the address. Leading zeroes are
- tolerated only for values less then 8 (as there is no ambiguity
+ tolerated only for values less than 8 (as there is no ambiguity
between the decimal and octal interpretations of such strings).
2. An integer that fits into 32 bits.
3. An integer packed into a :class:`bytes` object of length 4 (most
@@ -146,6 +146,20 @@ write code that handles both IP versions correctly.
the appropriate length (most significant octet first). This is 4 bytes
for IPv4 and 16 bytes for IPv6.
+ .. attribute:: reverse_pointer
+
+ The name of the reverse DNS PTR record for the IP address, e.g.::
+
+ >>> ipaddress.ip_address("127.0.0.1").reverse_pointer
+ '1.0.0.127.in-addr.arpa'
+ >>> ipaddress.ip_address("2001:db8::1").reverse_pointer
+ '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa'
+
+ This is the name that could be used for performing a PTR lookup, not the
+ resolved hostname itself.
+
+ .. versionadded:: 3.5
+
.. attribute:: is_multicast
``True`` if the address is reserved for multicast use. See
@@ -226,6 +240,7 @@ write code that handles both IP versions correctly.
:class:`IPv4Address` class:
.. attribute:: packed
+ .. attribute:: reverse_pointer
.. attribute:: version
.. attribute:: max_prefixlen
.. attribute:: is_multicast
@@ -377,6 +392,12 @@ so to avoid duplication they are only documented for :class:`IPv4Network`.
3. An integer packed into a :class:`bytes` object of length 4, big-endian.
The interpretation is similar to an integer *address*.
+ 4. A two-tuple of an address description and a netmask, where the address
+ description is either a string, a 32-bits integer, a 4-bytes packed
+ integer, or an existing IPv4Address object; and the netmask is either
+ an integer representing the prefix length (e.g. ``24``) or a string
+ representing the prefix mask (e.g. ``255.255.255.0``).
+
An :exc:`AddressValueError` is raised if *address* is not a valid IPv4
address. A :exc:`NetmaskValueError` is raised if the mask is not valid for
an IPv4 address.
@@ -389,6 +410,10 @@ so to avoid duplication they are only documented for :class:`IPv4Network`.
objects will raise :exc:`TypeError` if the argument's IP version is
incompatible to ``self``
+ .. versionchanged:: 3.5
+
+ Added the two-tuple form for the *address* constructor parameter.
+
.. attribute:: version
.. attribute:: max_prefixlen
@@ -553,6 +578,11 @@ so to avoid duplication they are only documented for :class:`IPv4Network`.
3. An integer packed into a :class:`bytes` object of length 16, bit-endian.
The interpretation is similar to an integer *address*.
+ 4. A two-tuple of an address description and a netmask, where the address
+ description is either a string, a 128-bits integer, a 16-bytes packed
+ integer, or an existing IPv4Address object; and the netmask is an
+ integer representing the prefix length.
+
An :exc:`AddressValueError` is raised if *address* is not a valid IPv6
address. A :exc:`NetmaskValueError` is raised if the mask is not valid for
an IPv6 address.
@@ -561,6 +591,10 @@ so to avoid duplication they are only documented for :class:`IPv4Network`.
then :exc:`ValueError` is raised. Otherwise, the host bits are masked out
to determine the appropriate network address.
+ .. versionchanged:: 3.5
+
+ Added the two-tuple form for the *address* constructor parameter.
+
.. attribute:: version
.. attribute:: max_prefixlen
.. attribute:: is_multicast
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index f489535c53..c5ba2eb596 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -87,10 +87,15 @@ loops that truncate the stream.
.. function:: accumulate(iterable[, func])
- Make an iterator that returns accumulated sums. Elements may be any addable
- type including :class:`~decimal.Decimal` or :class:`~fractions.Fraction`.
- If the optional *func* argument is supplied, it should be a function of two
- arguments and it will be used instead of addition.
+ Make an iterator that returns accumulated sums, or accumulated
+ results of other binary functions (specified via the optional
+ *func* argument). If *func* is supplied, it should be a function
+ of two arguments. Elements of the input *iterable* may be any type
+ that can be accepted as arguments to *func*. (For example, with
+ the default operation of addition, elements may be any addable
+ type including :class:`~decimal.Decimal` or
+ :class:`~fractions.Fraction`.) If the input iterable is empty, the
+ output iterable will also be empty.
Equivalent to::
@@ -657,6 +662,11 @@ which incur interpreter overhead.
"Return function(0), function(1), ..."
return map(function, count(start))
+ def tail(n, iterable):
+ "Return an iterator over the last n items"
+ # tail(3, 'ABCDEFG') --> E F G
+ return iter(collections.deque(iterable, maxlen=n))
+
def consume(iterator, n):
"Advance the iterator n-steps ahead. If n is none, consume entirely."
# Use functions that consume iterators at C speed.
diff --git a/Doc/library/json.rst b/Doc/library/json.rst
index 5d97ee88fc..d6bdd8a4f8 100644
--- a/Doc/library/json.rst
+++ b/Doc/library/json.rst
@@ -104,6 +104,8 @@ Using json.tool from the shell to validate and pretty-print::
$ echo '{1.2:3.4}' | python -mjson.tool
Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
+See :ref:`json-commandline` for detailed documentation.
+
.. highlight:: python3
.. note::
@@ -563,3 +565,54 @@ the last name-value pair for a given name::
{'x': 3}
The *object_pairs_hook* parameter can be used to alter this behavior.
+
+.. highlight:: bash
+
+.. _json-commandline:
+
+Command Line Interface
+----------------------
+
+The :mod:`json.tool` module provides a simple command line interface to validate
+and pretty-print JSON objects.
+
+If the optional :option:`infile` and :option:`outfile` arguments are not
+specified, :attr:`sys.stdin` and :attr:`sys.stdout` will be used respectively::
+
+ $ echo '{"json": "obj"}' | python -m json.tool
+ {
+ "json": "obj"
+ }
+ $ echo '{1.2:3.4}' | python -m json.tool
+ Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
+
+
+Command line options
+^^^^^^^^^^^^^^^^^^^^
+
+.. cmdoption:: infile
+
+ The JSON file to be validated or pretty-printed::
+
+ $ python -m json.tool mp_films.json
+ [
+ {
+ "title": "And Now for Something Completely Different",
+ "year": 1971
+ },
+ {
+ "title": "Monty Python and the Holy Grail",
+ "year": 1975
+ }
+ ]
+
+ If *infile* is not specified, read from :attr:`sys.stdin`.
+
+.. cmdoption:: outfile
+
+ Write the output of the *infile* to the given *outfile*. Otherwise, write it
+ to :attr:`sys.stdout`.
+
+.. cmdoption:: -h, --help
+
+ Show the help message.
diff --git a/Doc/library/logging.handlers.rst b/Doc/library/logging.handlers.rst
index a2b14de1b0..8c6d24b168 100644
--- a/Doc/library/logging.handlers.rst
+++ b/Doc/library/logging.handlers.rst
@@ -435,7 +435,7 @@ sends logging output to a network socket. The base class uses a TCP socket.
.. method:: createSocket()
Tries to create a socket; on failure, uses an exponential back-off
- algorithm. On intial failure, the handler will drop the message it was
+ algorithm. On initial failure, the handler will drop the message it was
trying to send. When subsequent messages are handled by the same
instance, it will not try connecting until some time has passed. The
default parameters are such that the initial delay is one second, and if
diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst
index 276339842c..243b10129a 100644
--- a/Doc/library/multiprocessing.rst
+++ b/Doc/library/multiprocessing.rst
@@ -1322,6 +1322,9 @@ processes.
Note that accessing the ctypes object through the wrapper can be a lot slower
than accessing the raw ctypes object.
+ .. versionchanged:: 3.5
+ Synchronized objects support the :term:`context manager` protocol.
+
The table below compares the syntax for creating shared ctypes objects from
shared memory with the normal ctypes syntax. (In the table ``MyStruct`` is some
diff --git a/Doc/library/operator.rst b/Doc/library/operator.rst
index 3bcbaa4b86..3654d133a8 100644
--- a/Doc/library/operator.rst
+++ b/Doc/library/operator.rst
@@ -138,6 +138,14 @@ The mathematical and bitwise operations are the most numerous:
Return ``a * b``, for *a* and *b* numbers.
+.. function:: matmul(a, b)
+ __matmul__(a, b)
+
+ Return ``a @ b``.
+
+ .. versionadded:: 3.5
+
+
.. function:: neg(obj)
__neg__(obj)
@@ -400,6 +408,8 @@ Python syntax and the functions in the :mod:`operator` module.
+-----------------------+-------------------------+---------------------------------------+
| Multiplication | ``a * b`` | ``mul(a, b)`` |
+-----------------------+-------------------------+---------------------------------------+
+| Matrix Multiplication | ``a @ b`` | ``matmul(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
| Negation (Arithmetic) | ``- a`` | ``neg(a)`` |
+-----------------------+-------------------------+---------------------------------------+
| Negation (Logical) | ``not a`` | ``not_(a)`` |
@@ -508,6 +518,14 @@ will perform the update, so no subsequent assignment is necessary:
``a = imul(a, b)`` is equivalent to ``a *= b``.
+.. function:: imatmul(a, b)
+ __imatmul__(a, b)
+
+ ``a = imatmul(a, b)`` is equivalent to ``a @= b``.
+
+ .. versionadded:: 3.5
+
+
.. function:: ior(a, b)
__ior__(a, b)
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
index 36dfc89146..9752fb3d1c 100644
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -1088,8 +1088,16 @@ or `the MSDN <http://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Window
All platforms support sockets as *out* file descriptor, and some platforms
allow other types (e.g. regular file, pipe) as well.
+ Cross-platform applications should not use *headers*, *trailers* and *flags*
+ arguments.
+
Availability: Unix.
+ .. note::
+
+ For a higher-level wrapper of :func:`sendfile`, see
+ :mod:`socket.socket.sendfile`.
+
.. versionadded:: 3.3
@@ -1891,6 +1899,11 @@ features:
* :attr:`st_gen` - file generation number
* :attr:`st_birthtime` - time of file creation
+ On Windows systems, the following attribute is also available:
+
+ * :attr:`st_file_attributes` - Windows file attribute bits (see the
+ ``FILE_ATTRIBUTE_*`` constants in the :mod:`stat` module)
+
.. note::
The exact meaning and resolution of the :attr:`st_atime`,
@@ -1944,6 +1957,9 @@ features:
and the :attr:`st_atime_ns`, :attr:`st_mtime_ns`,
and :attr:`st_ctime_ns` members.
+ .. versionadded:: 3.5
+ Added the :attr:`st_file_attributes` member on Windows.
+
.. function:: stat_float_times([newvalue])
@@ -2727,10 +2743,27 @@ written in Python, such as a mail server's external command delivery program.
Availability: Unix.
-.. function:: popen(...)
+.. function:: popen(command, mode='r', buffering=-1)
+
+ Open a pipe to or from *command*. The return value is an open file object
+ connected to the pipe, which can be read or written depending on whether *mode*
+ is ``'r'`` (default) or ``'w'``. The *buffering* argument has the same meaning as
+ the corresponding argument to the built-in :func:`open` function. The
+ returned file object reads or writes text strings rather than bytes.
+
+ The ``close`` method returns :const:`None` if the subprocess exited
+ successfully, or the subprocess's return code if there was an
+ error. On POSIX systems, if the return code is positive it
+ represents the return value of the process left-shifted by one
+ byte. If the return code is negative, the process was terminated
+ by the signal given by the negated value of the return code. (For
+ example, the return value might be ``- signal.SIGKILL`` if the
+ subprocess was killed.) On Windows systems, the return value
+ contains the signed integer return code from the child process.
- Run child processes, returning opened pipes for communications. These functions
- are described in section :ref:`os-newstreams`.
+ This is implemented using :class:`subprocess.Popen`; see that class's
+ documentation for more powerful ways to manage and communicate with
+ subprocesses.
.. function:: spawnl(mode, path, ...)
diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index ec1dc4f616..0a2a4e3be0 100644
--- a/Doc/library/pathlib.rst
+++ b/Doc/library/pathlib.rst
@@ -884,6 +884,25 @@ call fails (for example because the path doesn't exist):
Remove this directory. The directory must be empty.
+.. method:: Path.samefile(other_path)
+
+ Return whether this path points to the same file as *other_path*, which
+ can be either a Path object, or a string. The semantics are similar
+ to :func:`os.path.samefile` and :func:`os.path.samestat`.
+
+ An :exc:`OSError` can be raised if either file cannot be accessed for some
+ reason.
+
+ >>> p = Path('spam')
+ >>> q = Path('eggs')
+ >>> p.samefile(q)
+ False
+ >>> p.samefile('spam')
+ True
+
+ .. versionadded:: 3.5
+
+
.. method:: Path.symlink_to(target, target_is_directory=False)
Make this path a symbolic link to *target*. Under Windows,
diff --git a/Doc/library/pkgutil.rst b/Doc/library/pkgutil.rst
index 13ea7b9b33..5d3295db7e 100644
--- a/Doc/library/pkgutil.rst
+++ b/Doc/library/pkgutil.rst
@@ -58,7 +58,7 @@ support.
.. deprecated:: 3.3
This emulation is no longer needed, as the standard import mechanism
- is now fully PEP 302 compliant and available in :mod:`importlib`
+ is now fully PEP 302 compliant and available in :mod:`importlib`.
.. class:: ImpLoader(fullname, file, filename, etc)
@@ -67,7 +67,7 @@ support.
.. deprecated:: 3.3
This emulation is no longer needed, as the standard import mechanism
- is now fully PEP 302 compliant and available in :mod:`importlib`
+ is now fully PEP 302 compliant and available in :mod:`importlib`.
.. function:: find_loader(fullname)
diff --git a/Doc/library/plistlib.rst b/Doc/library/plistlib.rst
index 6a2d6b4971..b0d5bcf105 100644
--- a/Doc/library/plistlib.rst
+++ b/Doc/library/plistlib.rst
@@ -129,7 +129,7 @@ The following functions are deprecated:
and binary) file object. Returns the unpacked root object (which usually
is a dictionary).
- This function calls :func:`load` to do the actual work, the the documentation
+ This function calls :func:`load` to do the actual work, see the documentation
of :func:`that function <load>` for an explanation of the keyword arguments.
.. note::
diff --git a/Doc/library/random.rst b/Doc/library/random.rst
index 11dd367f8a..f8b772749f 100644
--- a/Doc/library/random.rst
+++ b/Doc/library/random.rst
@@ -46,8 +46,7 @@ from sources provided by the operating system.
.. warning::
The pseudo-random generators of this module should not be used for
- security purposes. Use :func:`os.urandom` or :class:`SystemRandom` if
- you require a cryptographically secure pseudo-random number generator.
+ security purposes.
Bookkeeping functions:
diff --git a/Doc/library/resource.rst b/Doc/library/resource.rst
index f8112cc0e4..7c0e4caf75 100644
--- a/Doc/library/resource.rst
+++ b/Doc/library/resource.rst
@@ -45,7 +45,7 @@ this module for those platforms.
.. data:: RLIM_INFINITY
- Constant used to represent the the limit for an unlimited resource.
+ Constant used to represent the limit for an unlimited resource.
.. function:: getrlimit(resource)
diff --git a/Doc/library/select.rst b/Doc/library/select.rst
index 973a0cc7d6..a5e0c133e9 100644
--- a/Doc/library/select.rst
+++ b/Doc/library/select.rst
@@ -210,7 +210,7 @@ object.
.. warning::
Registering a file descriptor that's already registered is not an
- error, but the result is undefined. The appropiate action is to
+ error, but the result is undefined. The appropriate action is to
unregister or modify it first. This is an important difference
compared with :c:func:`poll`.
diff --git a/Doc/library/selectors.rst b/Doc/library/selectors.rst
index 98377c890f..8bd9e1ce2e 100644
--- a/Doc/library/selectors.rst
+++ b/Doc/library/selectors.rst
@@ -45,6 +45,7 @@ Classes hierarchy::
+-- SelectSelector
+-- PollSelector
+-- EpollSelector
+ +-- DevpollSelector
+-- KqueueSelector
@@ -207,6 +208,16 @@ below:
This returns the file descriptor used by the underlying
:func:`select.epoll` object.
+.. class:: DevpollSelector()
+
+ :func:`select.devpoll`-based selector.
+
+ .. method:: fileno()
+
+ This returns the file descriptor used by the underlying
+ :func:`select.devpoll` object.
+
+ .. versionadded:: 3.5
.. class:: KqueueSelector()
diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst
index e4f348cd82..7a623677d3 100644
--- a/Doc/library/shutil.rst
+++ b/Doc/library/shutil.rst
@@ -191,7 +191,8 @@ Directory and files operations
match one of the glob-style *patterns* provided. See the example below.
-.. function:: copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2, ignore_dangling_symlinks=False)
+.. function:: copytree(src, dst, symlinks=False, ignore=None, \
+ copy_function=copy2, ignore_dangling_symlinks=False)
Recursively copy an entire directory tree rooted at *src*, returning the
destination directory. The destination
@@ -282,7 +283,7 @@ Directory and files operations
.. versionadded:: 3.3
-.. function:: move(src, dst)
+.. function:: move(src, dst, copy_function=copy2)
Recursively move a file or directory (*src*) to another location (*dst*)
and return the destination.
@@ -295,15 +296,26 @@ Directory and files operations
:func:`os.rename` semantics.
If the destination is on the current filesystem, then :func:`os.rename` is
- used. Otherwise, *src* is copied (using :func:`shutil.copy2`) to *dst* and
- then removed. In case of symlinks, a new symlink pointing to the target of
- *src* will be created in or as *dst* and *src* will be removed.
+ used. Otherwise, *src* is copied to *dst* using *copy_function* and then
+ removed. In case of symlinks, a new symlink pointing to the target of *src*
+ will be created in or as *dst* and *src* will be removed.
+
+ If *copy_function* is given, it must be a callable that takes two arguments
+ *src* and *dst*, and will be used to copy *src* to *dest* if
+ :func:`os.rename` cannot be used. If the source is a directory,
+ :func:`copytree` is called, passing it the :func:`copy_function`. The
+ default *copy_function* is :func:`copy2`. Using :func:`copy` as the
+ *copy_function* allows the move to succeed when it is not possible to also
+ copy the metadata, at the expense of not copying any of the metadata.
.. versionchanged:: 3.3
Added explicit symlink handling for foreign filesystems, thus adapting
it to the behavior of GNU's :program:`mv`.
Now returns *dst*.
+ .. versionchanged:: 3.5
+ Added the *copy_function* keyword argument.
+
.. function:: disk_usage(path)
Return disk usage statistics about the given path as a :term:`named tuple`
@@ -341,7 +353,7 @@ Directory and files operations
On Windows, the current directory is always prepended to the *path* whether
or not you use the default or provide your own, which is the behavior the
- command shell uses when finding executables. Additionaly, when finding the
+ command shell uses when finding executables. Additionally, when finding the
*cmd* in the *path*, the ``PATHEXT`` environment variable is checked. For
example, if you call ``shutil.which("python")``, :func:`which` will search
``PATHEXT`` to know that it should look for ``python.exe`` within the *path*
@@ -421,6 +433,26 @@ Another example that uses the *ignore* argument to add a logging call::
copytree(source, destination, ignore=_logpath)
+.. _shutil-rmtree-example:
+
+rmtree example
+~~~~~~~~~~~~~~
+
+This example shows how to remove a directory tree on Windows where some
+of the files have their read-only bit set. It uses the onerror callback
+to clear the readonly bit and reattempt the remove. Any subsequent failure
+will propagate. ::
+
+ import os, stat
+ import shutil
+
+ def remove_readonly(func, path, _):
+ "Clear the readonly bit and reattempt the removal"
+ os.chmod(path, stat.S_IWRITE)
+ func(path)
+
+ shutil.rmtree(directory, onerror=remove_readonly)
+
.. _archiving-operations:
Archiving operations
diff --git a/Doc/library/signal.rst b/Doc/library/signal.rst
index 84e283683d..a97ce66ef5 100644
--- a/Doc/library/signal.rst
+++ b/Doc/library/signal.rst
@@ -65,6 +65,16 @@ Besides, only the main thread is allowed to set a new signal handler.
Module contents
---------------
+.. versionchanged:: 3.5
+ signal (SIG*), handler (:const:`SIG_DFL`, :const:`SIG_IGN`) and sigmask
+ (:const:`SIG_BLOCK`, :const:`SIG_UNBLOCK`, :const:`SIG_SETMASK`)
+ related constants listed below were turned into
+ :class:`enums <enum.IntEnum>`.
+ :func:`getsignal`, :func:`pthread_sigmask`, :func:`sigpending` and
+ :func:`sigwait` functions return human-readable
+ :class:`enums <enum.IntEnum>`.
+
+
The variables defined in the :mod:`signal` module are:
diff --git a/Doc/library/site.rst b/Doc/library/site.rst
index e57b8ccc2d..43daf790b7 100644
--- a/Doc/library/site.rst
+++ b/Doc/library/site.rst
@@ -26,24 +26,23 @@ additions, call the :func:`site.main` function.
:option:`-S`.
.. index::
- pair: site-python; directory
pair: site-packages; directory
It starts by constructing up to four directories from a head and a tail part.
For the head part, it uses ``sys.prefix`` and ``sys.exec_prefix``; empty heads
are skipped. For the tail part, it uses the empty string and then
:file:`lib/site-packages` (on Windows) or
-:file:`lib/python{X.Y}/site-packages` and then :file:`lib/site-python` (on
-Unix and Macintosh). For each of the distinct head-tail combinations, it sees
-if it refers to an existing directory, and if so, adds it to ``sys.path`` and
-also inspects the newly added path for configuration files.
+:file:`lib/python{X.Y}/site-packages` (on Unix and Macintosh). For each
+of the distinct head-tail combinations, it sees if it refers to an existing
+directory, and if so, adds it to ``sys.path`` and also inspects the newly
+added path for configuration files.
-.. deprecated:: 3.4
- Support for the "site-python" directory will be removed in 3.5.
+.. versionchanged:: 3.5
+ Support for the "site-python" directory has been removed.
If a file named "pyvenv.cfg" exists one directory above sys.executable,
sys.prefix and sys.exec_prefix are set to that directory and
-it is also checked for site-packages and site-python (sys.base_prefix and
+it is also checked for site-packages (sys.base_prefix and
sys.base_exec_prefix will always be the "real" prefixes of the Python
installation). If "pyvenv.cfg" (a bootstrap configuration file) contains
the key "include-system-site-packages" set to anything other than "false"
@@ -184,7 +183,7 @@ Module contents
unless the Python interpreter was started with the :option:`-S` flag.
.. versionchanged:: 3.3
- This function used to be called unconditionnally.
+ This function used to be called unconditionally.
.. function:: addsitedir(sitedir, known_paths=None)
@@ -195,8 +194,7 @@ Module contents
.. function:: getsitepackages()
- Return a list containing all global site-packages directories (and possibly
- site-python).
+ Return a list containing all global site-packages directories.
.. versionadded:: 3.2
diff --git a/Doc/library/smtpd.rst b/Doc/library/smtpd.rst
index 3ebed06260..0f4a0bf512 100644
--- a/Doc/library/smtpd.rst
+++ b/Doc/library/smtpd.rst
@@ -28,7 +28,7 @@ SMTPServer Objects
.. class:: SMTPServer(localaddr, remoteaddr, data_size_limit=33554432,\
- map=None)
+ map=None, decode_data=True)
Create a new :class:`SMTPServer` object, which binds to local address
*localaddr*. It will treat *remoteaddr* as an upstream SMTP relayer. It
@@ -41,6 +41,11 @@ SMTPServer Objects
A dictionary can be specified in *map* to avoid using a global socket map.
+ *decode_data* specifies whether the data portion of the SMTP transaction
+ should be decoded using UTF-8. The default is ``True`` for backward
+ compatibility reasons, but will change to ``False`` in Python 3.6. Specify
+ the keyword value explicitly to avoid the :exc:`DeprecationWarning`.
+
.. method:: process_message(peer, mailfrom, rcpttos, data)
Raise :exc:`NotImplementedError` exception. Override this in subclasses to
@@ -51,6 +56,10 @@ SMTPServer Objects
containing the contents of the e-mail (which should be in :rfc:`2822`
format).
+ If the *decode_data* constructor keyword is set to ``True``, the *data*
+ argument will be a unicode string. If it is set to ``False``, it
+ will be a bytes object.
+
.. attribute:: channel_class
Override this in subclasses to use a custom :class:`SMTPChannel` for
@@ -59,6 +68,9 @@ SMTPServer Objects
.. versionchanged:: 3.4
The *map* argument was added.
+ .. versionchanged:: 3.5 the *decode_data* argument was added, and *localaddr*
+ and *remoteaddr* may now contain IPv6 addresses.
+
DebuggingServer Objects
-----------------------
@@ -97,7 +109,7 @@ SMTPChannel Objects
-------------------
.. class:: SMTPChannel(server, conn, addr, data_size_limit=33554432,\
- map=None))
+ map=None, decode_data=True)
Create a new :class:`SMTPChannel` object which manages the communication
between the server and a single SMTP client.
@@ -110,9 +122,17 @@ SMTPChannel Objects
A dictionary can be specified in *map* to avoid using a global socket map.
+ *decode_data* specifies whether the data portion of the SMTP transaction
+ should be decoded using UTF-8. The default is ``True`` for backward
+ compatibility reasons, but will change to ``False`` in Python 3.6. Specify
+ the keyword value explicitly to avoid the :exc:`DeprecationWarning`.
+
To use a custom SMTPChannel implementation you need to override the
:attr:`SMTPServer.channel_class` of your :class:`SMTPServer`.
+ .. versionchanged:: 3.5
+ the *decode_data* argument was added.
+
The :class:`SMTPChannel` has the following instance variables:
.. attribute:: smtp_server
diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst
index 8e1bfb57f9..74de77b94e 100644
--- a/Doc/library/smtplib.rst
+++ b/Doc/library/smtplib.rst
@@ -240,8 +240,7 @@ An :class:`SMTP` instance has the following methods:
the server is stored as the :attr:`ehlo_resp` attribute, :attr:`does_esmtp`
is set to true or false depending on whether the server supports ESMTP, and
:attr:`esmtp_features` will be a dictionary containing the names of the
- SMTP service extensions this server supports, and their
- parameters (if any).
+ SMTP service extensions this server supports, and their parameters (if any).
Unless you wish to use :meth:`has_extn` before sending mail, it should not be
necessary to call this method explicitly. It will be implicitly called by
@@ -291,6 +290,42 @@ An :class:`SMTP` instance has the following methods:
:exc:`SMTPException`
No suitable authentication method was found.
+ Each of the authentication methods supported by :mod:`smtplib` are tried in
+ turn if they are advertised as supported by the server (see :meth:`auth`
+ for a list of supported authentication methods).
+
+
+.. method:: SMTP.auth(mechanism, authobject)
+
+ Issue an ``SMTP`` ``AUTH`` command for the specified authentication
+ *mechanism*, and handle the challenge response via *authobject*.
+
+ *mechanism* specifies which authentication mechanism is to
+ be used as argument to the ``AUTH`` command; the valid values are
+ those listed in the ``auth`` element of :attr:`esmtp_features`.
+
+ *authobject* must be a callable object taking a single argument:
+
+ data = authobject(challenge)
+
+ It will be called to process the server's challenge response; the
+ *challenge* argument it is passed will be a ``bytes``. It should return
+ ``bytes`` *data* that will be base64 encoded and sent to the server.
+
+ The ``SMTP`` class provides ``authobjects`` for the ``CRAM-MD5``, ``PLAIN``,
+ and ``LOGIN`` mechanisms; they are named ``SMTP.auth_cram_md5``,
+ ``SMTP.auth_plain``, and ``SMTP.auth_login`` respectively. They all require
+ that the ``user`` and ``password`` properties of the ``SMTP`` instance are
+ set to appropriate values.
+
+ User code does not normally need to call ``auth`` directly, but can instead
+ call the :meth:`login` method, which will try each of the above mechanisms in
+ turn, in the order listed. ``auth`` is exposed to facilitate the
+ implementation of authentication methods not (or not yet) supported directly
+ by :mod:`smtplib`.
+
+ .. versionadded:: 3.5
+
.. method:: SMTP.starttls(keyfile=None, certfile=None, context=None)
diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst
index 54c6badb13..ceeb776795 100644
--- a/Doc/library/socket.rst
+++ b/Doc/library/socket.rst
@@ -906,12 +906,15 @@ to sockets.
On other platforms, the generic :func:`fcntl.fcntl` and :func:`fcntl.ioctl`
functions may be used; they accept a socket object as their first argument.
-.. method:: socket.listen(backlog)
+.. method:: socket.listen([backlog])
- Listen for connections made to the socket. The *backlog* argument specifies the
- maximum number of queued connections and should be at least 0; the maximum value
- is system-dependent (usually 5), the minimum value is forced to 0.
+ Enable a server to accept connections. If *backlog* is specified, it must
+ be at least 0 (if it is lower, it is set to 0); it specifies the number of
+ unaccepted connections that the system will allow before refusing new
+ connections. If not specified, a default reasonable value is chosen.
+ .. versionchanged:: 3.5
+ The *backlog* parameter is now optional.
.. method:: socket.makefile(mode='r', buffering=None, *, encoding=None, \
errors=None, newline=None)
@@ -1145,6 +1148,21 @@ to sockets.
.. versionadded:: 3.3
+.. method:: socket.sendfile(file, offset=0, count=None)
+
+ Send a file until EOF is reached by using high-performance
+ :mod:`os.sendfile` and return the total number of bytes which were sent.
+ *file* must be a regular file object opened in binary mode. If
+ :mod:`os.sendfile` is not available (e.g. Windows) or *file* is not a
+ regular file :meth:`send` will be used instead. *offset* tells from where to
+ start reading the file. If specified, *count* is the total number of bytes
+ to transmit as opposed to sending the file until EOF is reached. File
+ position is updated on return or also in case of error in which case
+ :meth:`file.tell() <io.IOBase.tell>` can be used to figure out the number of
+ bytes which were sent. The socket must be of :const:`SOCK_STREAM` type. Non-
+ blocking sockets are not supported.
+
+ .. versionadded:: 3.5
.. method:: socket.set_inheritable(inheritable)
@@ -1444,7 +1462,7 @@ After binding (:const:`CAN_RAW`) or connecting (:const:`CAN_BCM`) the socket, yo
can use the :meth:`socket.send`, and the :meth:`socket.recv` operations (and
their counterparts) on the socket object as usual.
-This example might require special priviledge::
+This example might require special privileges::
import socket
import struct
diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst
index 1ec44389bf..9db36d5510 100644
--- a/Doc/library/socketserver.rst
+++ b/Doc/library/socketserver.rst
@@ -113,7 +113,7 @@ the request handler class :meth:`handle` method.
Another approach to handling multiple simultaneous requests in an environment
that supports neither threads nor :func:`~os.fork` (or where these are too
expensive or inappropriate for the service) is to maintain an explicit table of
-partially finished requests and to use :func:`~select.select` to decide which
+partially finished requests and to use :mod:`selectors` to decide which
request to work on next (or whether to handle a new incoming request). This is
particularly important for stream services where each client can potentially be
connected for a long time (if threads or subprocesses cannot be used). See
@@ -136,7 +136,7 @@ Server Objects
.. method:: BaseServer.fileno()
Return an integer file descriptor for the socket on which the server is
- listening. This function is most commonly passed to :func:`select.select`, to
+ listening. This function is most commonly passed to :mod:`selectors`, to
allow monitoring multiple servers in the same process.
diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst
index b473c45a4b..75b5d28e9e 100644
--- a/Doc/library/ssl.rst
+++ b/Doc/library/ssl.rst
@@ -372,22 +372,34 @@ Certificate handling
IDN A-labels such as ``www*.xn--pthon-kva.org`` are still supported,
but ``x*.python.org`` no longer matches ``xn--tda.python.org``.
-.. function:: cert_time_to_seconds(timestring)
+.. function:: cert_time_to_seconds(cert_time)
- Returns a floating-point value containing a normal seconds-after-the-epoch
- time value, given the time-string representing the "notBefore" or "notAfter"
- date from a certificate.
+ Return the time in seconds since the Epoch, given the ``cert_time``
+ string representing the "notBefore" or "notAfter" date from a
+ certificate in ``"%b %d %H:%M:%S %Y %Z"`` strptime format (C
+ locale).
- Here's an example::
+ Here's an example:
- >>> import ssl
- >>> ssl.cert_time_to_seconds("May 9 00:00:00 2007 GMT")
- 1178694000.0
- >>> import time
- >>> time.ctime(ssl.cert_time_to_seconds("May 9 00:00:00 2007 GMT"))
- 'Wed May 9 00:00:00 2007'
+ .. doctest:: newcontext
-.. function:: get_server_certificate(addr, ssl_version=PROTOCOL_SSLv3, ca_certs=None)
+ >>> import ssl
+ >>> timestamp = ssl.cert_time_to_seconds("Jan 5 09:34:43 2018 GMT")
+ >>> timestamp
+ 1515144883
+ >>> from datetime import datetime
+ >>> print(datetime.utcfromtimestamp(timestamp))
+ 2018-01-05 09:34:43
+
+ "notBefore" or "notAfter" dates must use GMT (:rfc:`5280`).
+
+ .. versionchanged:: 3.5
+ Interpret the input time as a time in UTC as specified by 'GMT'
+ timezone in the input string. Local timezone was used
+ previously. Return an integer (no fractions of a second in the
+ input format)
+
+.. function:: get_server_certificate(addr, ssl_version=PROTOCOL_SSLv23, ca_certs=None)
Given the address ``addr`` of an SSL-protected server, as a (*hostname*,
*port-number*) pair, fetches the server's certificate, and returns it as a
@@ -401,6 +413,10 @@ Certificate handling
.. versionchanged:: 3.3
This function is now IPv6-compatible.
+ .. versionchanged:: 3.5
+ The default *ssl_version* is changed from :data:`PROTOCOL_SSLv3` to
+ :data:`PROTOCOL_SSLv23` for maximum compatibility with modern servers.
+
.. function:: DER_cert_to_PEM_cert(DER_cert_bytes)
Given a certificate as a DER-encoded blob of bytes, returns a PEM-encoded
@@ -773,6 +789,11 @@ SSL sockets provide the following methods of :ref:`socket-objects`:
(but passing a non-zero ``flags`` argument is not allowed)
- :meth:`~socket.socket.send()`, :meth:`~socket.socket.sendall()` (with
the same limitation)
+- :meth:`~socket.socket.sendfile()` (but :mod:`os.sendfile` will be used
+ for plain-text sockets only, else :meth:`~socket.socket.send()` will be used)
+
+ .. versionadded:: 3.5
+
- :meth:`~socket.socket.shutdown()`
However, since the SSL (and TLS) protocol has its own framing atop
@@ -1005,7 +1026,7 @@ to speed up repeated connections from the same clients.
:data:`CERT_NONE`. At least one of *cafile* or *capath* must be specified.
This method can also load certification revocation lists (CRLs) in PEM or
- or DER format. In order to make use of CRLs, :attr:`SSLContext.verify_flags`
+ DER format. In order to make use of CRLs, :attr:`SSLContext.verify_flags`
must be configured properly.
The *cafile* string, if present, is the path to a file of concatenated
@@ -1602,6 +1623,12 @@ thus several things you need to be aware of:
socket first, and attempts to *read* from the SSL socket may require
a prior *write* to the underlying socket.
+ .. versionchanged:: 3.5
+
+ In earlier Python versions, the :meth:`!SSLSocket.send` method
+ returned zero instead of raising :exc:`SSLWantWriteError` or
+ :exc:`SSLWantReadError`.
+
- Calling :func:`~select.select` tells you that the OS-level socket can be
read from (or written to), but it does not imply that there is sufficient
data at the upper SSL layer. For example, only part of an SSL frame might
@@ -1671,7 +1698,7 @@ Manual settings
Verifying certificates
''''''''''''''''''''''
-When calling the the :class:`SSLContext` constructor directly,
+When calling the :class:`SSLContext` constructor directly,
:const:`CERT_NONE` is the default. Since it does not authenticate the other
peer, it can be insecure, especially in client mode where most of time you
would like to ensure the authenticity of the server you're talking to.
diff --git a/Doc/library/stat.rst b/Doc/library/stat.rst
index 24769f6893..845b2ef7da 100644
--- a/Doc/library/stat.rst
+++ b/Doc/library/stat.rst
@@ -126,7 +126,7 @@ Example::
if __name__ == '__main__':
walktree(sys.argv[1], visitfile)
-An additional utility function is provided to covert a file's mode in a human
+An additional utility function is provided to convert a file's mode in a human
readable string:
.. function:: filemode(mode)
@@ -399,3 +399,29 @@ The following flags can be used in the *flags* argument of :func:`os.chflags`:
The file is a snapshot file.
See the \*BSD or Mac OS systems man page :manpage:`chflags(2)` for more information.
+
+On Windows, the following file attribute constants are available for use when
+testing bits in the ``st_file_attributes`` member returned by :func:`os.stat`.
+See the `Windows API documentation
+<http://msdn.microsoft.com/en-us/library/windows/desktop/gg258117.aspx>`_
+for more detail on the meaning of these constants.
+
+.. data:: FILE_ATTRIBUTE_ARCHIVE
+ FILE_ATTRIBUTE_COMPRESSED
+ FILE_ATTRIBUTE_DEVICE
+ FILE_ATTRIBUTE_DIRECTORY
+ FILE_ATTRIBUTE_ENCRYPTED
+ FILE_ATTRIBUTE_HIDDEN
+ FILE_ATTRIBUTE_INTEGRITY_STREAM
+ FILE_ATTRIBUTE_NORMAL
+ FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
+ FILE_ATTRIBUTE_NO_SCRUB_DATA
+ FILE_ATTRIBUTE_OFFLINE
+ FILE_ATTRIBUTE_READONLY
+ FILE_ATTRIBUTE_REPARSE_POINT
+ FILE_ATTRIBUTE_SPARSE_FILE
+ FILE_ATTRIBUTE_SYSTEM
+ FILE_ATTRIBUTE_TEMPORARY
+ FILE_ATTRIBUTE_VIRTUAL
+
+ .. versionadded:: 3.5
diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst
index 854993cba0..d76e29ff7b 100644
--- a/Doc/library/subprocess.rst
+++ b/Doc/library/subprocess.rst
@@ -629,6 +629,7 @@ Instances of the :class:`Popen` class have the following methods:
must be bytes or, if *universal_newlines* was ``True``, a string.
:meth:`communicate` returns a tuple ``(stdoutdata, stderrdata)``.
+ The data will be bytes or, if *universal_newlines* was ``True``, strings.
Note that if you want to send data to the process's stdin, you need to create
the Popen object with ``stdin=PIPE``. Similarly, to get anything other than
diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst
index d78159d64b..4ad7d9c555 100644
--- a/Doc/library/tempfile.rst
+++ b/Doc/library/tempfile.rst
@@ -54,6 +54,13 @@ The module defines the following user-callable items:
underlying true file object. This file-like object can be used in a
:keyword:`with` statement, just like a normal file.
+ The :py:data:`os.O_TMPFILE` flag is used if it is available and works
+ (Linux-specific, require Linux kernel 3.11 or later).
+
+ .. versionchanged:: 3.5
+
+ The :py:data:`os.O_TMPFILE` flag is now used if available.
+
.. function:: NamedTemporaryFile(mode='w+b', buffering=None, encoding=None, newline=None, suffix='', prefix='tmp', dir=None, delete=True)
diff --git a/Doc/library/threading.rst b/Doc/library/threading.rst
index 4a3b3ea00b..03ee769bb0 100644
--- a/Doc/library/threading.rst
+++ b/Doc/library/threading.rst
@@ -630,7 +630,7 @@ item to the buffer only needs to wake up one consumer thread.
cv.wait()
Therefore, the same rules apply as with :meth:`wait`: The lock must be
- held when called and is re-aquired on return. The predicate is evaluated
+ held when called and is re-acquired on return. The predicate is evaluated
with the lock held.
.. versionadded:: 3.2
diff --git a/Doc/library/tkinter.ttk.rst b/Doc/library/tkinter.ttk.rst
index 6f8bf1c315..b0eefcb702 100644
--- a/Doc/library/tkinter.ttk.rst
+++ b/Doc/library/tkinter.ttk.rst
@@ -1167,7 +1167,7 @@ Ttk Styling
Each widget in :mod:`ttk` is assigned a style, which specifies the set of
elements making up the widget and how they are arranged, along with dynamic
and default settings for element options. By default the style name is the
-same as the widget's class name, but it may be overriden by the widget's style
+same as the widget's class name, but it may be overridden by the widget's style
option. If you don't know the class name of a widget, use the method
:meth:`Misc.winfo_class` (somewidget.winfo_class()).
diff --git a/Doc/library/token.rst b/Doc/library/token.rst
index 4cd709814c..88fb38bc1d 100644
--- a/Doc/library/token.rst
+++ b/Doc/library/token.rst
@@ -93,6 +93,7 @@ The token constants are:
DOUBLESLASH
DOUBLESLASHEQUAL
AT
+ ATEQUAL
RARROW
ELLIPSIS
OP
diff --git a/Doc/library/tracemalloc.rst b/Doc/library/tracemalloc.rst
index 3405518ab2..f1e260278d 100644
--- a/Doc/library/tracemalloc.rst
+++ b/Doc/library/tracemalloc.rst
@@ -350,7 +350,7 @@ Functions
the *nframe* parameter of the :func:`start` function to store more frames.
The :mod:`tracemalloc` module must be tracing memory allocations to take a
- snapshot, see the the :func:`start` function.
+ snapshot, see the :func:`start` function.
See also the :func:`get_object_traceback` function.
diff --git a/Doc/library/turtle.rst b/Doc/library/turtle.rst
index b015530cca..dbb1aa9e1f 100644
--- a/Doc/library/turtle.rst
+++ b/Doc/library/turtle.rst
@@ -1809,7 +1809,7 @@ Input methods
Pop up a dialog window for input of a number. title is the title of the
dialog window, prompt is a text mostly describing what numerical information
- to input. default: default value, minval: minimum value for imput,
+ to input. default: default value, minval: minimum value for input,
maxval: maximum value for input
The number input must be in the range minval .. maxval if these are
given. If not, a hint is issued and the dialog remains open for
@@ -1879,7 +1879,7 @@ Settings and special methods
>>> cv = screen.getcanvas()
>>> cv
- <turtle.ScrolledCanvas object at ...>
+ <turtle.ScrolledCanvas object ...>
.. function:: getshapes()
@@ -2397,7 +2397,7 @@ Changes since Python 3.0
Accordingly the latter has got an alias: :meth:`Screen.onkeyrelease`.
- The method :meth:`Screen.mainloop` has been added. So when working only
- with Screen and Turtle objects one must not additonally import
+ with Screen and Turtle objects one must not additionally import
:func:`mainloop` anymore.
- Two input methods has been added :meth:`Screen.textinput` and
diff --git a/Doc/library/types.rst b/Doc/library/types.rst
index abdb939d1a..34fffe6863 100644
--- a/Doc/library/types.rst
+++ b/Doc/library/types.rst
@@ -115,6 +115,10 @@ Standard names are defined for the following types:
The type of :term:`modules <module>`. Constructor takes the name of the
module to be created and optionally its :term:`docstring`.
+ .. note::
+ Use :func:`importlib.util.module_from_spec` to create a new module if you
+ wish to set the various import-controlled attributes.
+
.. attribute:: __doc__
The :term:`docstring` of the module. Defaults to ``None``.
diff --git a/Doc/library/unicodedata.rst b/Doc/library/unicodedata.rst
index 3b3d3a0a8f..24ddef8a32 100644
--- a/Doc/library/unicodedata.rst
+++ b/Doc/library/unicodedata.rst
@@ -15,8 +15,8 @@
This module provides access to the Unicode Character Database (UCD) which
defines character properties for all Unicode characters. The data contained in
-this database is compiled from the `UCD version 6.3.0
-<http://www.unicode.org/Public/6.3.0/ucd>`_.
+this database is compiled from the `UCD version 7.0.0
+<http://www.unicode.org/Public/7.0.0/ucd>`_.
The module uses the same names and symbols as defined by Unicode
Standard Annex #44, `"Unicode Character Database"
@@ -166,6 +166,6 @@ Examples:
.. rubric:: Footnotes
-.. [#] http://www.unicode.org/Public/6.3.0/ucd/NameAliases.txt
+.. [#] http://www.unicode.org/Public/7.0.0/ucd/NameAliases.txt
-.. [#] http://www.unicode.org/Public/6.3.0/ucd/NamedSequences.txt
+.. [#] http://www.unicode.org/Public/7.0.0/ucd/NamedSequences.txt
diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst
index cb72a683dd..4f58892443 100644
--- a/Doc/library/unittest.mock.rst
+++ b/Doc/library/unittest.mock.rst
@@ -198,7 +198,7 @@ a `MagicMock` for you. You can specify an alternative class of `Mock` using
the `new_callable` argument to `patch`.
-.. class:: Mock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, **kwargs)
+.. class:: Mock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, **kwargs)
Create a new `Mock` object. `Mock` takes several optional arguments
that specify the behaviour of the Mock object:
@@ -235,6 +235,12 @@ the `new_callable` argument to `patch`.
this is a new Mock (created on first access). See the
:attr:`return_value` attribute.
+ * `unsafe`: By default if any attribute starts with *assert* or
+ *assret* will raise an `AttributeError`. Passing `unsafe=True` will allow
+ access to these attributes.
+
+ .. versionadded:: 3.5
+
* `wraps`: Item for the mock object to wrap. If `wraps` is not None then
calling the Mock will pass the call through to the wrapped object
(returning the real result). Attribute access on the mock will return a
@@ -315,6 +321,20 @@ the `new_callable` argument to `patch`.
>>> calls = [call(4), call(2), call(3)]
>>> mock.assert_has_calls(calls, any_order=True)
+ .. method:: assert_not_called(*args, **kwargs)
+
+ Assert the mock was never called.
+
+ >>> m = Mock()
+ >>> m.hello.assert_not_called()
+ >>> obj = m.hello()
+ >>> m.hello.assert_not_called()
+ Traceback (most recent call last):
+ ...
+ AssertionError: Expected 'hello' to not have been called. Called 1 times.
+
+ .. versionadded:: 3.5
+
.. method:: reset_mock()
@@ -1031,6 +1051,12 @@ patch
default because it can be dangerous. With it switched on you can write
passing tests against APIs that don't actually exist!
+ .. note::
+
+ .. versionchanged:: 3.5
+ If you are patching builtins in a module then you don't
+ need to pass `create=True`, it will be added by default.
+
Patch can be used as a `TestCase` class decorator. It works by
decorating each test method in the class. This reduces the boilerplate
code when your test methods share a common patchings set. `patch` finds
@@ -1401,6 +1427,21 @@ It is also possible to stop all patches which have been started by using
Stop all active patches. Only stops patches started with `start`.
+.. patch-builtins:
+
+patch builtins
+~~~~~~~~~~~~~~~
+You can patch any builtins within a module. The following example patches
+builtin `ord`:
+
+ >>> @patch('__main__.ord')
+ ... def test(mock_ord):
+ ... mock_ord.return_value = 101
+ ... print(ord('c'))
+ ...
+ >>> test()
+ 101
+
TEST_PREFIX
~~~~~~~~~~~
@@ -2011,7 +2052,7 @@ Mocking context managers with a :class:`MagicMock` is common enough and fiddly
enough that a helper function is useful.
>>> m = mock_open()
- >>> with patch('__main__.open', m, create=True):
+ >>> with patch('__main__.open', m):
... with open('foo', 'w') as h:
... h.write('some stuff')
...
@@ -2026,7 +2067,7 @@ enough that a helper function is useful.
And for reading files:
- >>> with patch('__main__.open', mock_open(read_data='bibble'), create=True) as m:
+ >>> with patch('__main__.open', mock_open(read_data='bibble')) as m:
... with open('foo') as h:
... result = h.read()
...
diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst
index 019f59cfbc..b588dad3a3 100644
--- a/Doc/library/urllib.request.rst
+++ b/Doc/library/urllib.request.rst
@@ -67,7 +67,7 @@ The :mod:`urllib.request` module defines the following functions:
:class:`http.client.HTTPResponse` object which has the following
:ref:`httpresponse-objects` methods.
- For ftp, file, and data urls and requests explicity handled by legacy
+ For ftp, file, and data urls and requests explicitly handled by legacy
:class:`URLopener` and :class:`FancyURLopener` classes, this function
returns a :class:`urllib.response.addinfourl` object which can work as
:term:`context manager` and has methods such as
@@ -1067,7 +1067,7 @@ The following W3C document, http://www.w3.org/International/O-charset\ , lists
the various ways in which a (X)HTML or a XML document could have specified its
encoding information.
-As the python.org website uses *utf-8* encoding as specified in it's meta tag, we
+As the python.org website uses *utf-8* encoding as specified in its meta tag, we
will use the same for decoding the bytes object. ::
>>> with urllib.request.urlopen('http://www.python.org/') as f:
diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst
index 9ca60a903f..cc883b1b51 100644
--- a/Doc/library/weakref.rst
+++ b/Doc/library/weakref.rst
@@ -566,8 +566,8 @@ third party, such as running code when a module is unloaded::
.. note::
- If you create a finalizer object in a daemonic thread just as the
- the program exits then there is the possibility that the finalizer
+ If you create a finalizer object in a daemonic thread just as the program
+ exits then there is the possibility that the finalizer
does not get called at exit. However, in a daemonic thread
:func:`atexit.register`, ``try: ... finally: ...`` and ``with: ...``
do not guarantee that cleanup occurs either.
diff --git a/Doc/library/webbrowser.rst b/Doc/library/webbrowser.rst
index ef63769999..aa5e4ad15d 100644
--- a/Doc/library/webbrowser.rst
+++ b/Doc/library/webbrowser.rst
@@ -20,7 +20,7 @@ available. If text-mode browsers are used, the calling process will block until
the user exits the browser.
If the environment variable :envvar:`BROWSER` exists, it is interpreted as the
-:data:`os.pathsep`-separated list of browsers to try ahead of the the platform
+:data:`os.pathsep`-separated list of browsers to try ahead of the platform
defaults. When the value of a list part contains the string ``%s``, then it is
interpreted as a literal browser command line to be used with the argument URL
substituted for ``%s``; if the part does not contain ``%s``, it is simply
diff --git a/Doc/library/wsgiref.rst b/Doc/library/wsgiref.rst
index 1cef2e9464..223814030f 100644
--- a/Doc/library/wsgiref.rst
+++ b/Doc/library/wsgiref.rst
@@ -184,10 +184,11 @@ This module provides a single class, :class:`Headers`, for convenient
manipulation of WSGI response headers using a mapping-like interface.
-.. class:: Headers(headers)
+.. class:: Headers([headers])
Create a mapping-like object wrapping *headers*, which must be a list of header
- name/value tuples as described in :pep:`3333`.
+ name/value tuples as described in :pep:`3333`. The default value of *headers* is
+ an empty list.
:class:`Headers` objects support typical mapping operations including
:meth:`__getitem__`, :meth:`get`, :meth:`__setitem__`, :meth:`setdefault`,
@@ -251,6 +252,10 @@ manipulation of WSGI response headers using a mapping-like interface.
Content-Disposition: attachment; filename="bud.gif"
+ .. versionchanged:: 3.5
+ *headers* parameter is optional.
+
+
:mod:`wsgiref.simple_server` -- a simple WSGI HTTP server
---------------------------------------------------------
diff --git a/Doc/library/xml.dom.rst b/Doc/library/xml.dom.rst
index 19512ed3f7..4914738dfc 100644
--- a/Doc/library/xml.dom.rst
+++ b/Doc/library/xml.dom.rst
@@ -412,7 +412,7 @@ objects:
.. method:: NodeList.item(i)
Return the *i*'th item from the sequence, if there is one, or ``None``. The
- index *i* is not allowed to be less then zero or greater than or equal to the
+ index *i* is not allowed to be less than zero or greater than or equal to the
length of the sequence.
diff --git a/Doc/library/xmlrpc.client.rst b/Doc/library/xmlrpc.client.rst
index 3cb19d1862..6f14227ea9 100644
--- a/Doc/library/xmlrpc.client.rst
+++ b/Doc/library/xmlrpc.client.rst
@@ -191,6 +191,11 @@ grouped under the reserved :attr:`system` attribute:
no such string is available, an empty string is returned. The documentation
string may contain HTML markup.
+.. versionchanged:: 3.5
+
+ Instances of :class:`ServerProxy` support the :term:`context manager` protocol
+ for closing the underlying transport.
+
A working example follows. The server code::
@@ -208,9 +213,9 @@ The client code for the preceding server::
import xmlrpc.client
- proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
- print("3 is even: %s" % str(proxy.is_even(3)))
- print("100 is even: %s" % str(proxy.is_even(100)))
+ with xmlrpc.client.ServerProxy("http://localhost:8000/") as proxy:
+ print("3 is even: %s" % str(proxy.is_even(3)))
+ print("100 is even: %s" % str(proxy.is_even(100)))
.. _datetime-objects:
@@ -518,14 +523,14 @@ Example of Client Usage
from xmlrpc.client import ServerProxy, Error
# server = ServerProxy("http://localhost:8000") # local server
- server = ServerProxy("http://betty.userland.com")
+ with ServerProxy("http://betty.userland.com") as proxy:
- print(server)
+ print(proxy)
- try:
- print(server.examples.getStateName(41))
- except Error as v:
- print("ERROR", v)
+ try:
+ print(proxy.examples.getStateName(41))
+ except Error as v:
+ print("ERROR", v)
To access an XML-RPC server through a proxy, you need to define a custom
transport. The following example shows how: