Skip to content
3.5.txt 77.7 KiB
Newer Older
Ryott Glayzer's avatar
Ryott Glayzer committed
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000
----

The "Enum" callable has a new parameter *start* to specify the initial
number of enum values if only *names* are provided:

   >>> Animal = enum.Enum('Animal', 'cat dog', start=10)
   >>> Animal.cat
   <Animal.cat: 10>
   >>> Animal.dog
   <Animal.dog: 11>

(Contributed by Ethan Furman in bpo-21706.)


faulthandler
------------

The "enable()", "register()", "dump_traceback()" and
"dump_traceback_later()" functions now accept file descriptors in
addition to file-like objects. (Contributed by Wei Wu in bpo-23566.)


functools
---------

Most of the "lru_cache()" machinery is now implemented in C, making it
significantly faster.  (Contributed by Matt Joiner, Alexey Kachayev,
and Serhiy Storchaka in bpo-14373.)


glob
----

The "iglob()" and "glob()" functions now support recursive search in
subdirectories, using the ""**"" pattern. (Contributed by Serhiy
Storchaka in bpo-13968.)


gzip
----

The *mode* argument of the "GzipFile" constructor now accepts ""x"" to
request exclusive creation. (Contributed by Tim Heaney in bpo-19222.)


heapq
-----

Element comparison in "merge()" can now be customized by passing a
*key function* in a new optional *key* keyword argument, and a new
optional *reverse* keyword argument can be used to reverse element
comparison:

   >>> import heapq
   >>> a = ['9', '777', '55555']
   >>> b = ['88', '6666']
   >>> list(heapq.merge(a, b, key=len))
   ['9', '88', '777', '6666', '55555']
   >>> list(heapq.merge(reversed(a), reversed(b), key=len, reverse=True))
   ['55555', '6666', '777', '88', '9']

(Contributed by Raymond Hettinger in bpo-13742.)


http
----

A new "HTTPStatus" enum that defines a set of HTTP status codes,
reason phrases and long descriptions written in English. (Contributed
by Demian Brecht in bpo-21793.)


http.client
-----------

"HTTPConnection.getresponse()" now raises a "RemoteDisconnected"
exception when a remote server connection is closed unexpectedly.
Additionally, if a "ConnectionError" (of which "RemoteDisconnected" is
a subclass) is raised, the client socket is now closed automatically,
and will reconnect on the next request:

   import http.client
   conn = http.client.HTTPConnection('www.python.org')
   for retries in range(3):
       try:
           conn.request('GET', '/')
           resp = conn.getresponse()
       except http.client.RemoteDisconnected:
           pass

(Contributed by Martin Panter in bpo-3566.)


idlelib and IDLE
----------------

Since idlelib implements the IDLE shell and editor and is not intended
for import by other programs, it gets improvements with every release.
See "Lib/idlelib/NEWS.txt" for a cumulative list of changes since
3.4.0, as well as changes made in future 3.5.x releases. This file is
also available from the IDLE Help ‣ About IDLE dialog.


imaplib
-------

The "IMAP4" class now supports the *context manager* protocol. When
used in a "with" statement, the IMAP4 "LOGOUT" command will be called
automatically at the end of the block. (Contributed by Tarek Ziadé and
Serhiy Storchaka in bpo-4972.)

The "imaplib" module now supports **RFC 5161** (ENABLE Extension) and
**RFC 6855** (UTF-8 Support) via the "IMAP4.enable()" method.  A new
"IMAP4.utf8_enabled" attribute tracks whether or not **RFC 6855**
support is enabled. (Contributed by Milan Oberkirch, R. David Murray,
and Maciej Szulik in bpo-21800.)

The "imaplib" module now automatically encodes non-ASCII string
usernames and passwords using UTF-8, as recommended by the RFCs.
(Contributed by Milan Oberkirch in bpo-21800.)


imghdr
------

The "what()" function now recognizes the OpenEXR format (contributed
by Martin Vignali and Claudiu Popa in bpo-20295), and the WebP format
(contributed by Fabrice Aneche and Claudiu Popa in bpo-20197.)


importlib
---------

The "util.LazyLoader" class allows for lazy loading of modules in
applications where startup time is important. (Contributed by Brett
Cannon in bpo-17621.)

The "abc.InspectLoader.source_to_code()" method is now a static
method.  This makes it easier to initialize a module object with code
compiled from a string by running "exec(code, module.__dict__)".
(Contributed by Brett Cannon in bpo-21156.)

The new "util.module_from_spec()" function is now the preferred way to
create a new module.  As opposed to creating a "types.ModuleType"
instance directly, this new function will set the various import-
controlled attributes based on the passed-in spec object.
(Contributed by Brett Cannon in bpo-20383.)


inspect
-------

Both the "Signature" and "Parameter" classes are now picklable and
hashable.  (Contributed by Yury Selivanov in bpo-20726 and bpo-20334.)

A new "BoundArguments.apply_defaults()" method provides a way to set
default values for missing arguments:

   >>> def foo(a, b='ham', *args): pass
   >>> ba = inspect.signature(foo).bind('spam')
   >>> ba.apply_defaults()
   >>> ba.arguments
   OrderedDict([('a', 'spam'), ('b', 'ham'), ('args', ())])

(Contributed by Yury Selivanov in bpo-24190.)

A new class method "Signature.from_callable()" makes subclassing of
"Signature" easier.  (Contributed by Yury Selivanov and Eric Snow in
bpo-17373.)

The "signature()" function now accepts a *follow_wrapped* optional
keyword argument, which, when set to "False", disables automatic
following of "__wrapped__" links. (Contributed by Yury Selivanov in
bpo-20691.)

A set of new functions to inspect *coroutine functions* and *coroutine
objects* has been added: "iscoroutine()", "iscoroutinefunction()",
"isawaitable()", "getcoroutinelocals()", and "getcoroutinestate()".
(Contributed by Yury Selivanov in bpo-24017 and bpo-24400.)

The "stack()", "trace()", "getouterframes()", and "getinnerframes()"
functions now return a list of named tuples. (Contributed by Daniel
Shahaf in bpo-16808.)


io
--

A new "BufferedIOBase.readinto1()" method, that uses at most one call
to the underlying raw stream's "RawIOBase.read()" or
"RawIOBase.readinto()" methods. (Contributed by Nikolaus Rath in
bpo-20578.)


ipaddress
---------

Both the "IPv4Network" and "IPv6Network" classes now accept an
"(address, netmask)" tuple argument, so as to easily construct network
objects from existing addresses:

   >>> import ipaddress
   >>> ipaddress.IPv4Network(('127.0.0.0', 8))
   IPv4Network('127.0.0.0/8')
   >>> ipaddress.IPv4Network(('127.0.0.0', '255.0.0.0'))
   IPv4Network('127.0.0.0/8')

(Contributed by Peter Moody and Antoine Pitrou in bpo-16531.)

A new "reverse_pointer" attribute for the "IPv4Network" and
"IPv6Network" classes returns the name of the reverse DNS PTR record:

   >>> import ipaddress
   >>> addr = ipaddress.IPv4Address('127.0.0.1')
   >>> addr.reverse_pointer
   '1.0.0.127.in-addr.arpa'
   >>> addr6 = ipaddress.IPv6Address('::1')
   >>> addr6.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.0.0.0.0.0.0.0.0.ip6.arpa'

(Contributed by Leon Weber in bpo-20480.)


json
----

The "json.tool" command line interface now preserves the order of keys
in JSON objects passed in input.  The new "--sort-keys" option can be
used to sort the keys alphabetically. (Contributed by Berker Peksag in
bpo-21650.)

JSON decoder now raises "JSONDecodeError" instead of "ValueError" to
provide better context information about the error. (Contributed by
Serhiy Storchaka in bpo-19361.)


linecache
---------

A new "lazycache()" function can be used to capture information about
a non-file-based module to permit getting its lines later via
"getline()". This avoids doing I/O until a line is actually needed,
without having to carry the module globals around indefinitely.
(Contributed by Robert Collins in bpo-17911.)


locale
------

A new "delocalize()" function can be used to convert a string into a
normalized number string, taking the "LC_NUMERIC" settings into
account:

   >>> import locale
   >>> locale.setlocale(locale.LC_NUMERIC, 'de_DE.UTF-8')
   'de_DE.UTF-8'
   >>> locale.delocalize('1.234,56')
   '1234.56'
   >>> locale.setlocale(locale.LC_NUMERIC, 'en_US.UTF-8')
   'en_US.UTF-8'
   >>> locale.delocalize('1,234.56')
   '1234.56'

(Contributed by Cédric Krier in bpo-13918.)


logging
-------

All logging methods ("Logger" "log()", "exception()", "critical()",
"debug()", etc.), now accept exception instances as an *exc_info*
argument, in addition to boolean values and exception tuples:

   >>> import logging
   >>> try:
   ...     1/0
   ... except ZeroDivisionError as ex:
   ...     logging.error('exception', exc_info=ex)
   ERROR:root:exception

(Contributed by Yury Selivanov in bpo-20537.)

The "handlers.HTTPHandler" class now accepts an optional
"ssl.SSLContext" instance to configure SSL settings used in an HTTP
connection. (Contributed by Alex Gaynor in bpo-22788.)

The "handlers.QueueListener" class now takes a *respect_handler_level*
keyword argument which, if set to "True", will pass messages to
handlers taking handler levels into account. (Contributed by Vinay
Sajip.)


lzma
----

The "LZMADecompressor.decompress()" method now accepts an optional
*max_length* argument to limit the maximum size of decompressed data.
(Contributed by Martin Panter in bpo-15955.)


math
----

Two new constants have been added to the "math" module: "inf" and
"nan".  (Contributed by Mark Dickinson in bpo-23185.)

A new function "isclose()" provides a way to test for approximate
equality. (Contributed by Chris Barker and Tal Einat in bpo-24270.)

A new "gcd()" function has been added.  The "fractions.gcd()" function
is now deprecated. (Contributed by Mark Dickinson and Serhiy Storchaka
in bpo-22486.)


multiprocessing
---------------

"sharedctypes.synchronized()" objects now support the *context
manager* protocol. (Contributed by Charles-François Natali in
bpo-21565.)


operator
--------

"attrgetter()", "itemgetter()", and "methodcaller()" objects now
support pickling. (Contributed by Josh Rosenberg and Serhiy Storchaka
in bpo-22955.)

New "matmul()" and "imatmul()" functions to perform matrix
multiplication. (Contributed by Benjamin Peterson in bpo-21176.)


os
--

The new "scandir()" function returning an iterator of "DirEntry"
objects has been added.  If possible, "scandir()" extracts file
attributes while scanning a directory, removing the need to perform
subsequent system calls to determine file type or attributes, which
may significantly improve performance.  (Contributed by Ben Hoyt with
the help of Victor Stinner in bpo-22524.)

On Windows, a new "stat_result.st_file_attributes" attribute is now
available.  It corresponds to the "dwFileAttributes" member of the
"BY_HANDLE_FILE_INFORMATION" structure returned by
"GetFileInformationByHandle()".  (Contributed by Ben Hoyt in
bpo-21719.)

The "urandom()" function now uses the "getrandom()" syscall on Linux
3.17 or newer, and "getentropy()" on OpenBSD 5.6 and newer, removing
the need to use "/dev/urandom" and avoiding failures due to potential
file descriptor exhaustion.  (Contributed by Victor Stinner in
bpo-22181.)

New "get_blocking()" and "set_blocking()" functions allow getting and
setting a file descriptor's blocking mode ("O_NONBLOCK".) (Contributed
by Victor Stinner in bpo-22054.)

The "truncate()" and "ftruncate()" functions are now supported on
Windows.  (Contributed by Steve Dower in bpo-23668.)

There is a new "os.path.commonpath()" function returning the longest
common sub-path of each passed pathname.  Unlike the
"os.path.commonprefix()" function, it always returns a valid path:

   >>> os.path.commonprefix(['/usr/lib', '/usr/local/lib'])
   '/usr/l'

   >>> os.path.commonpath(['/usr/lib', '/usr/local/lib'])
   '/usr'

(Contributed by Rafik Draoui and Serhiy Storchaka in bpo-10395.)


pathlib
-------

The new "Path.samefile()" method can be used to check whether the path
points to the same file as another path, which can be either another
"Path" object, or a string:

   >>> import pathlib
   >>> p1 = pathlib.Path('/etc/hosts')
   >>> p2 = pathlib.Path('/etc/../etc/hosts')
   >>> p1.samefile(p2)
   True

(Contributed by Vajrasky Kok and Antoine Pitrou in bpo-19775.)

The "Path.mkdir()" method now accepts a new optional *exist_ok*
argument to match "mkdir -p" and "os.makedirs()" functionality.
(Contributed by Berker Peksag in bpo-21539.)

There is a new "Path.expanduser()" method to expand "~" and "~user"
prefixes.  (Contributed by Serhiy Storchaka and Claudiu Popa in
bpo-19776.)

A new "Path.home()" class method can be used to get a "Path" instance
representing the user’s home directory. (Contributed by Victor Salgado
and Mayank Tripathi in bpo-19777.)

New "Path.write_text()", "Path.read_text()", "Path.write_bytes()",
"Path.read_bytes()" methods to simplify read/write operations on
files.

The following code snippet will create or rewrite existing file
"~/spam42":

   >>> import pathlib
   >>> p = pathlib.Path('~/spam42')
   >>> p.expanduser().write_text('ham')
   3

(Contributed by Christopher Welborn in bpo-20218.)


pickle
------

Nested objects, such as unbound methods or nested classes, can now be
pickled using pickle protocols older than protocol version 4. Protocol
version 4 already supports these cases.  (Contributed by Serhiy
Storchaka in bpo-23611.)


poplib
------

A new "POP3.utf8()" command enables **RFC 6856** (Internationalized
Email) support, if a POP server supports it. (Contributed by Milan
OberKirch in bpo-21804.)


re
--

References and conditional references to groups with fixed length are
now allowed in lookbehind assertions:

   >>> import re
   >>> pat = re.compile(r'(a|b).(?<=\1)c')
   >>> pat.match('aac')
   <_sre.SRE_Match object; span=(0, 3), match='aac'>
   >>> pat.match('bbc')
   <_sre.SRE_Match object; span=(0, 3), match='bbc'>

(Contributed by Serhiy Storchaka in bpo-9179.)

The number of capturing groups in regular expressions is no longer
limited to 100.  (Contributed by Serhiy Storchaka in bpo-22437.)

The "sub()" and "subn()" functions now replace unmatched groups with
empty strings instead of raising an exception. (Contributed by Serhiy
Storchaka in bpo-1519638.)

The "re.error" exceptions have new attributes, "msg", "pattern",
"pos", "lineno", and "colno", that provide better context information
about the error:

   >>> re.compile("""
   ...     (?x)
   ...     .++
   ... """)
   Traceback (most recent call last):
      ...
   sre_constants.error: multiple repeat at position 16 (line 3, column 7)

(Contributed by Serhiy Storchaka in bpo-22578.)


readline
--------

A new "append_history_file()" function can be used to append the
specified number of trailing elements in history to the given file.
(Contributed by Bruno Cauet in bpo-22940.)


selectors
---------

The new "DevpollSelector" supports efficient "/dev/poll" polling on
Solaris. (Contributed by Giampaolo Rodola' in bpo-18931.)


shutil
------

The "move()" function now accepts a *copy_function* argument,
allowing, for example, the "copy()" function to be used instead of the
default "copy2()" if there is a need to ignore file metadata when
moving. (Contributed by Claudiu Popa in bpo-19840.)

The "make_archive()" function now supports the *xztar* format.
(Contributed by Serhiy Storchaka in bpo-5411.)


signal
------

On Windows, the "set_wakeup_fd()" function now also supports socket
handles.  (Contributed by Victor Stinner in bpo-22018.)

Various "SIG*" constants in the "signal" module have been converted
into "Enums".  This allows meaningful names to be printed during
debugging, instead of integer "magic numbers". (Contributed by
Giampaolo Rodola' in bpo-21076.)


smtpd
-----

Both the "SMTPServer" and "SMTPChannel" classes now accept a
*decode_data* keyword argument to determine if the "DATA" portion of
the SMTP transaction is decoded using the ""utf-8"" codec or is
instead provided to the "SMTPServer.process_message()" method as a
byte string.  The default is "True" for backward compatibility
reasons, but will change to "False" in Python 3.6.  If *decode_data*
is set to "False", the "process_message" method must be prepared to
accept keyword arguments. (Contributed by Maciej Szulik in bpo-19662.)

The "SMTPServer" class now advertises the "8BITMIME" extension (**RFC
6152**) if *decode_data* has been set "True".  If the client specifies
"BODY=8BITMIME" on the "MAIL" command, it is passed to
"SMTPServer.process_message()" via the *mail_options* keyword.
(Contributed by Milan Oberkirch and R.  David Murray in bpo-21795.)

The "SMTPServer" class now also supports the "SMTPUTF8" extension
(**RFC 6531**: Internationalized Email).  If the client specified
"SMTPUTF8 BODY=8BITMIME" on the "MAIL" command, they are passed to
"SMTPServer.process_message()" via the *mail_options* keyword.  It is
the responsibility of the "process_message" method to correctly handle
the "SMTPUTF8" data. (Contributed by Milan Oberkirch in bpo-21725.)

It is now possible to provide, directly or via name resolution, IPv6
addresses in the "SMTPServer" constructor, and have it successfully
connect.  (Contributed by Milan Oberkirch in bpo-14758.)


smtplib
-------

A new "SMTP.auth()" method provides a convenient way to implement
custom authentication mechanisms. (Contributed by Milan Oberkirch in
bpo-15014.)

The "SMTP.set_debuglevel()" method now accepts an additional
debuglevel (2), which enables timestamps in debug messages.
(Contributed by Gavin Chappell and Maciej Szulik in bpo-16914.)

Both the "SMTP.sendmail()" and "SMTP.send_message()" methods now
support **RFC 6531** (SMTPUTF8). (Contributed by Milan Oberkirch and
R. David Murray in bpo-22027.)


sndhdr
------

The "what()" and "whathdr()" functions  now return a "namedtuple()".
(Contributed by Claudiu Popa in bpo-18615.)


socket
------

Functions with timeouts now use a monotonic clock, instead of a system
clock. (Contributed by Victor Stinner in bpo-22043.)

A new "socket.sendfile()" method allows sending a file over a socket
by using the high-performance "os.sendfile()" function on UNIX,
resulting in uploads being from 2 to 3 times faster than when using
plain "socket.send()". (Contributed by Giampaolo Rodola' in
bpo-17552.)

The "socket.sendall()" method no longer resets the socket timeout
every time bytes are received or sent.  The socket timeout is now the
maximum total duration to send all data. (Contributed by Victor
Stinner in bpo-23853.)

The *backlog* argument of the "socket.listen()" method is now
optional.  By default it is set to "SOMAXCONN" or to "128", whichever
is less. (Contributed by Charles-François Natali in bpo-21455.)


ssl
---


Memory BIO Support
~~~~~~~~~~~~~~~~~~

(Contributed by Geert Jansen in bpo-21965.)

The new "SSLObject" class has been added to provide SSL protocol
support for cases when the network I/O capabilities of "SSLSocket" are
not necessary or are suboptimal.  "SSLObject" represents an SSL
protocol instance, but does not implement any network I/O methods, and
instead provides a memory buffer interface.  The new "MemoryBIO" class
can be used to pass data between Python and an SSL protocol instance.

The memory BIO SSL support is primarily intended to be used in
frameworks implementing asynchronous I/O for which "SSLSocket"'s
readiness model ("select/poll") is inefficient.

A new "SSLContext.wrap_bio()" method can be used to create a new
"SSLObject" instance.


Application-Layer Protocol Negotiation Support
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(Contributed by Benjamin Peterson in bpo-20188.)

Where OpenSSL support is present, the "ssl" module now implements the
*Application-Layer Protocol Negotiation* TLS extension as described in
**RFC 7301**.

The new "SSLContext.set_alpn_protocols()" can be used to specify which
protocols a socket should advertise during the TLS handshake.

The new "SSLSocket.selected_alpn_protocol()" returns the protocol that
was selected during the TLS handshake. The "HAS_ALPN" flag indicates
whether ALPN support is present.


Other Changes
~~~~~~~~~~~~~

There is a new "SSLSocket.version()" method to query the actual
protocol version in use. (Contributed by Antoine Pitrou in bpo-20421.)

The "SSLSocket" class now implements a "SSLSocket.sendfile()" method.
(Contributed by Giampaolo Rodola' in bpo-17552.)

The "SSLSocket.send()" method now raises either the
"ssl.SSLWantReadError" or "ssl.SSLWantWriteError" exception on a non-
blocking socket if the operation would block. Previously, it would
return "0".  (Contributed by Nikolaus Rath in bpo-20951.)

The "cert_time_to_seconds()" function now interprets the input time as
UTC and not as local time, per **RFC 5280**.  Additionally, the return
value is always an "int". (Contributed by Akira Li in bpo-19940.)

New "SSLObject.shared_ciphers()" and "SSLSocket.shared_ciphers()"
methods return the list of ciphers sent by the client during the
handshake. (Contributed by Benjamin Peterson in bpo-23186.)

The "SSLSocket.do_handshake()", "SSLSocket.read()",
"SSLSocket.shutdown()", and "SSLSocket.write()" methods of the
"SSLSocket" class no longer reset the socket timeout every time bytes
are received or sent. The socket timeout is now the maximum total
duration of the method. (Contributed by Victor Stinner in bpo-23853.)

The "match_hostname()" function now supports matching of IP addresses.
(Contributed by Antoine Pitrou in bpo-23239.)


sqlite3
-------

The "Row" class now fully supports the sequence protocol, in
particular "reversed()" iteration and slice indexing. (Contributed by
Claudiu Popa in bpo-10203; by Lucas Sinclair, Jessica McKellar, and
Serhiy Storchaka in bpo-13583.)


subprocess
----------

The new "run()" function has been added. It runs the specified command
and returns a "CompletedProcess" object, which describes a finished
process.  The new API is more consistent and is the recommended
approach to invoking subprocesses in Python code that does not need to
maintain compatibility with earlier Python versions. (Contributed by
Thomas Kluyver in bpo-23342.)

Examples:

   >>> subprocess.run(["ls", "-l"])  # doesn't capture output
   CompletedProcess(args=['ls', '-l'], returncode=0)

   >>> subprocess.run("exit 1", shell=True, check=True)
   Traceback (most recent call last):
     ...
   subprocess.CalledProcessError: Command 'exit 1' returned non-zero exit status 1

   >>> subprocess.run(["ls", "-l", "/dev/null"], stdout=subprocess.PIPE)
   CompletedProcess(args=['ls', '-l', '/dev/null'], returncode=0,
   stdout=b'crw-rw-rw- 1 root root 1, 3 Jan 23 16:23 /dev/null\n')


sys
---

A new "set_coroutine_wrapper()" function allows setting a global hook
that will be called whenever a *coroutine object* is created by an
"async def" function.  A corresponding "get_coroutine_wrapper()" can
be used to obtain a currently set wrapper.  Both functions are
*provisional*, and are intended for debugging purposes only.
(Contributed by Yury Selivanov in bpo-24017.)

A new "is_finalizing()" function can be used to check if the Python
interpreter is *shutting down*. (Contributed by Antoine Pitrou in
bpo-22696.)


sysconfig
---------

The name of the user scripts directory on Windows now includes the
first two components of the Python version. (Contributed by Paul Moore
in bpo-23437.)


tarfile
-------

The *mode* argument of the "open()" function now accepts ""x"" to
request exclusive creation.  (Contributed by Berker Peksag in
bpo-21717.)

The "TarFile.extractall()" and "TarFile.extract()" methods now take a
keyword argument *numeric_owner*.  If set to "True", the extracted
files and directories will be owned by the numeric "uid" and "gid"
from the tarfile. If set to "False" (the default, and the behavior in
versions prior to 3.5), they will be owned by the named user and group
in the tarfile. (Contributed by Michael Vogt and Eric Smith in
bpo-23193.)

The "TarFile.list()" now accepts an optional *members* keyword
argument that can be set to a subset of the list returned by
"TarFile.getmembers()". (Contributed by Serhiy Storchaka in
bpo-21549.)


threading
---------

Both the "Lock.acquire()" and "RLock.acquire()" methods now use a
monotonic clock for timeout management. (Contributed by Victor Stinner
in bpo-22043.)


time
----

The "monotonic()" function is now always available. (Contributed by
Victor Stinner in bpo-22043.)


timeit
------

A new command line option "-u" or "--unit=*U*" can be used to specify
the time unit for the timer output.  Supported options are "usec",
"msec", or "sec".  (Contributed by Julian Gindi in bpo-18983.)

The "timeit()" function has a new *globals* parameter for specifying
the namespace in which the code will be running. (Contributed by Ben
Roberts in bpo-2527.)


tkinter
-------

The "tkinter._fix" module used for setting up the Tcl/Tk environment
on Windows has been replaced by a private function in the "_tkinter"
module which makes no permanent changes to environment variables.
(Contributed by Zachary Ware in bpo-20035.)


traceback
---------

New "walk_stack()" and "walk_tb()" functions to conveniently traverse
frame and traceback objects. (Contributed by Robert Collins in
bpo-17911.)

New lightweight classes: "TracebackException", "StackSummary", and
"FrameSummary". (Contributed by Robert Collins in bpo-17911.)

Both the "print_tb()" and "print_stack()" functions now support
negative values for the *limit* argument. (Contributed by Dmitry
Kazakov in bpo-22619.)


types
-----

A new "coroutine()" function to transform *generator* and "generator-
like" objects into *awaitables*. (Contributed by Yury Selivanov in
bpo-24017.)

A new type called "CoroutineType", which is used for *coroutine*
objects created by "async def" functions. (Contributed by Yury
Selivanov in bpo-24400.)


unicodedata
-----------

The "unicodedata" module now uses data from Unicode 8.0.0.


unittest
--------

The "TestLoader.loadTestsFromModule()" method now accepts a keyword-
only argument *pattern* which is passed to "load_tests" as the third
argument.  Found packages are now checked for "load_tests" regardless
of whether their path matches *pattern*, because it is impossible for
a package name to match the default pattern. (Contributed by Robert
Collins and Barry A. Warsaw in bpo-16662.)

Unittest discovery errors now are exposed in the "TestLoader.errors"
attribute of the "TestLoader" instance. (Contributed by Robert Collins
in bpo-19746.)

A new command line option "--locals" to show local variables in
tracebacks.  (Contributed by Robert Collins in bpo-22936.)


unittest.mock
-------------

The "Mock" class has the following improvements:

* The class constructor has a new *unsafe* parameter, which causes
  mock objects to raise "AttributeError" on attribute names starting
  with ""assert"". (Contributed by Kushal Das in bpo-21238.)

* A new "Mock.assert_not_called()" method to check if the mock object
  was called. (Contributed by Kushal Das in bpo-21262.)

The "MagicMock" class now supports "__truediv__()", "__divmod__()" and
"__matmul__()" operators. (Contributed by Johannes Baiter in
bpo-20968, and Håkan Lövdahl in bpo-23581 and bpo-23568.)

It is no longer necessary to explicitly pass "create=True" to the
"patch()" function when patching builtin names. (Contributed by Kushal
Das in bpo-17660.)


urllib
------

A new "request.HTTPPasswordMgrWithPriorAuth" class allows HTTP Basic
Authentication credentials to be managed so as to eliminate
unnecessary "401" response handling, or to unconditionally send
credentials on the first request in order to communicate with servers
that return a "404" response instead of a "401" if the "Authorization"
header is not sent. (Contributed by Matej Cepl in bpo-19494 and Akshit
Khurana in bpo-7159.)

A new *quote_via* argument for the "parse.urlencode()" function
provides a way to control the encoding of query parts if needed.
(Contributed by Samwyse and Arnon Yaari in bpo-13866.)

The "request.urlopen()" function accepts an "ssl.SSLContext" object as
a *context* argument, which will be used for the HTTPS connection.
(Contributed by Alex Gaynor in bpo-22366.)

The "parse.urljoin()" was updated to use the **RFC 3986** semantics
for the resolution of relative URLs, rather than **RFC 1808** and
**RFC 2396**. (Contributed by Demian Brecht and Senthil Kumaran in
bpo-22118.)


wsgiref
-------

The *headers* argument of the "headers.Headers" class constructor is
now optional. (Contributed by Pablo Torres Navarrete and SilentGhost
in bpo-5800.)


xmlrpc
------

The "client.ServerProxy" class now supports the *context manager*
protocol. (Contributed by Claudiu Popa in bpo-20627.)

The "client.ServerProxy" constructor now accepts an optional
"ssl.SSLContext" instance. (Contributed by Alex Gaynor in bpo-22960.)


xml.sax
-------

SAX parsers now support a character stream of the
"xmlreader.InputSource" object. (Contributed by Serhiy Storchaka in
bpo-2175.)

"parseString()" now accepts a "str" instance. (Contributed by Serhiy
Storchaka in bpo-10590.)


zipfile
-------

ZIP output can now be written to unseekable streams. (Contributed by
Serhiy Storchaka in bpo-23252.)

The *mode* argument of "ZipFile.open()" method now accepts ""x"" to
request exclusive creation. (Contributed by Serhiy Storchaka in
bpo-21717.)


Other module-level changes
==========================

Many functions in the "mmap", "ossaudiodev", "socket", "ssl", and
"codecs" modules now accept writable *bytes-like objects*.
(Contributed by Serhiy Storchaka in bpo-23001.)


Optimizations
=============

The "os.walk()" function has been sped up by 3 to 5 times on POSIX
systems, and by 7 to 20 times on Windows.  This was done using the new
"os.scandir()" function, which exposes file information from the
underlying "readdir" or "FindFirstFile"/"FindNextFile" system calls.
(Contributed by Ben Hoyt with help from Victor Stinner in bpo-23605.)

Construction of "bytes(int)" (filled by zero bytes) is faster and uses
less memory for large objects. "calloc()" is used instead of
"malloc()" to allocate memory for these objects. (Contributed by
Victor Stinner in bpo-21233.)

Some operations on "ipaddress" "IPv4Network" and "IPv6Network" have
been massively sped up, such as "subnets()", "supernet()",
"summarize_address_range()", "collapse_addresses()". The speed up can
range from 3 to 15 times. (Contributed by Antoine Pitrou, Michel
Albert, and Markus in bpo-21486, bpo-21487, bpo-20826, bpo-23266.)

Pickling of "ipaddress" objects was optimized to produce significantly
smaller output.  (Contributed by Serhiy Storchaka in bpo-23133.)

Many operations on "io.BytesIO" are now 50% to 100% faster.
(Contributed by Serhiy Storchaka in bpo-15381 and David Wilson in
bpo-22003.)

The "marshal.dumps()" function is now faster: 65--85% with versions 3
and 4, 20--25% with versions 0 to 2 on typical data, and up to 5 times
in best cases. (Contributed by Serhiy Storchaka in bpo-20416 and
bpo-23344.)

The UTF-32 encoder is now 3 to 7 times faster. (Contributed by Serhiy
Storchaka in bpo-15027.)

Regular expressions are now parsed up to 10% faster. (Contributed by
Serhiy Storchaka in bpo-19380.)

The "json.dumps()" function was optimized to run with
"ensure_ascii=False" as fast as with "ensure_ascii=True". (Contributed
by Naoki Inada in bpo-23206.)

The "PyObject_IsInstance()" and "PyObject_IsSubclass()" functions have
been sped up in the common case that the second argument has "type" as
its metaclass. (Contributed Georg Brandl by in bpo-22540.)

Method caching was slightly improved, yielding up to 5% performance
improvement in some benchmarks. (Contributed by Antoine Pitrou in
bpo-22847.)

Objects from the "random" module now use 50% less memory on 64-bit
builds.  (Contributed by Serhiy Storchaka in bpo-23488.)

The "property()" getter calls are up to 25% faster. (Contributed by
Joe Jevnik in bpo-23910.)

Instantiation of "fractions.Fraction" is now up to 30% faster.
(Contributed by Stefan Behnel in bpo-22464.)

String methods "find()", "rfind()", "split()", "partition()" and the
"in" string operator are now significantly faster for searching
1-character substrings. (Contributed by Serhiy Storchaka in
bpo-23573.)


Build and C API Changes
=======================

New "calloc" functions were added:

* "PyMem_RawCalloc()",

* "PyMem_Calloc()",

* "PyObject_Calloc()".

(Contributed by Victor Stinner in bpo-21233.)

New encoding/decoding helper functions:

* "Py_DecodeLocale()" (replaced "_Py_char2wchar()"),

* "Py_EncodeLocale()" (replaced "_Py_wchar2char()").