Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cc9ef11

Browse files
committed
Merge remote-tracking branch 'origin/2.7' into intl-2.7
2 parents 2c8e9a1 + c498cd8 commit cc9ef11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+576
-113
lines changed

Doc/c-api/sequence.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ Sequence Protocol
1717
1818
.. index:: builtin: len
1919
20-
Returns the number of objects in sequence *o* on success, and ``-1`` on failure.
21-
For objects that do not provide sequence protocol, this is equivalent to the
22-
Python expression ``len(o)``.
20+
Returns the number of objects in sequence *o* on success, and ``-1`` on
21+
failure. This is equivalent to the Python expression ``len(o)``.
2322
2423
.. versionchanged:: 2.5
2524
These functions returned an :c:type:`int` type. This might require

Doc/library/ssl.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ to speed up repeated connections from the same clients.
13301330

13311331
import socket, ssl
13321332

1333-
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
1333+
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
13341334
context.verify_mode = ssl.CERT_REQUIRED
13351335
context.check_hostname = True
13361336
context.load_default_certs()
@@ -1536,7 +1536,7 @@ If you prefer to tune security settings yourself, you might create
15361536
a context from scratch (but beware that you might not get the settings
15371537
right)::
15381538

1539-
>>> context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
1539+
>>> context = ssl.SSLContext(ssl.PROTOCOL_TLS)
15401540
>>> context.verify_mode = ssl.CERT_REQUIRED
15411541
>>> context.check_hostname = True
15421542
>>> context.load_verify_locations("/etc/ssl/certs/ca-bundle.crt")
@@ -1808,6 +1808,23 @@ successful call of :func:`~ssl.RAND_add`, :func:`~ssl.RAND_bytes` or
18081808
:func:`~ssl.RAND_pseudo_bytes` is sufficient.
18091809

18101810

1811+
.. ssl-libressl:
1812+
1813+
LibreSSL support
1814+
----------------
1815+
1816+
LibreSSL is a fork of OpenSSL 1.0.1. The ssl module has limited support for
1817+
LibreSSL. Some features are not available when the ssl module is compiled
1818+
with LibreSSL.
1819+
1820+
* LibreSSL >= 2.6.1 no longer supports NPN. The methods
1821+
:meth:`SSLContext.set_npn_protocols` and
1822+
:meth:`SSLSocket.selected_npn_protocol` are not available.
1823+
* :meth:`SSLContext.set_default_verify_paths` ignores the env vars
1824+
:envvar:`SSL_CERT_FILE` and :envvar:`SSL_CERT_PATH` although
1825+
:func:`get_default_verify_paths` still reports them.
1826+
1827+
18111828
.. seealso::
18121829

18131830
Class :class:`socket.socket`

Doc/library/unittest.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@ handling functionality within test frameworks.
20382038

20392039
When called without arguments this function removes the control-c handler
20402040
if it has been installed. This function can also be used as a test decorator
2041-
to temporarily remove the handler whilst the test is being executed::
2041+
to temporarily remove the handler while the test is being executed::
20422042

20432043
@unittest.removeHandler
20442044
def test_signal_handling(self):

Doc/tutorial/inputoutput.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Here are two ways to write a table of squares and cubes::
101101
10 100 1000
102102

103103
(Note that in the first example, one space between each column was added by the
104-
way :keyword:`print` works: it always adds spaces between its arguments.)
104+
way :keyword:`print` works: by default it adds spaces between its arguments.)
105105

106106
This example demonstrates the :meth:`str.rjust` method of string
107107
objects, which right-justifies a string in a field of a given width by padding

Doc/tutorial/interpreter.rst

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,7 @@ The Interpreter and Its Environment
126126
Source Code Encoding
127127
--------------------
128128

129-
By default, Python source files are treated as encoded in UTF-8. In that
130-
encoding, characters of most languages in the world can be used simultaneously
131-
in string literals, identifiers and comments --- although the standard library
132-
only uses ASCII characters for identifiers, a convention that any portable code
133-
should follow. To display all these characters properly, your editor must
134-
recognize that the file is UTF-8, and it must use a font that supports all the
135-
characters in the file.
136-
129+
By default, Python source files are treated as encoded in ASCII.
137130
To declare an encoding other than the default one, a special comment line
138131
should be added as the *first* line of the file. The syntax is as follows::
139132

Doc/tutorial/modules.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,25 @@ Note that in general the practice of importing ``*`` from a module or package is
108108
frowned upon, since it often causes poorly readable code. However, it is okay to
109109
use it to save typing in interactive sessions.
110110

111+
If the module name is followed by :keyword:`as`, then the name
112+
following :keyword:`as` is bound directly to the imported module.
113+
114+
::
115+
116+
>>> import fibo as fib
117+
>>> fib.fib(500)
118+
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
119+
120+
This is effectively importing the module in the same way that ``import fibo``
121+
will do, with the only difference of it being available as ``fib``.
122+
123+
It can also be used when utilising :keyword:`from` with similar effects::
124+
125+
>>> from fibo import fib as fibonacci
126+
>>> fibonacci(500)
127+
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
128+
129+
111130
.. note::
112131

113132
For efficiency reasons, each module is only imported once per interpreter

Doc/whatsnew/2.6.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2607,7 +2607,7 @@ changes, or look through the Subversion logs for all the details.
26072607

26082608
* The XML-RPC :class:`~SimpleXMLRPCServer.SimpleXMLRPCServer` and :class:`~DocXMLRPCServer.DocXMLRPCServer`
26092609
classes can now be prevented from immediately opening and binding to
2610-
their socket by passing True as the ``bind_and_activate``
2610+
their socket by passing ``False`` as the *bind_and_activate*
26112611
constructor parameter. This can be used to modify the instance's
26122612
:attr:`allow_reuse_address` attribute before calling the
26132613
:meth:`server_bind` and :meth:`server_activate` methods to

Lib/_threading_local.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@
5757
5858
>>> class MyLocal(local):
5959
... number = 2
60-
... initialized = False
6160
... def __init__(self, **kw):
62-
... if self.initialized:
63-
... raise SystemError('__init__ called too many times')
64-
... self.initialized = True
6561
... self.__dict__.update(kw)
6662
... def squared(self):
6763
... return self.number ** 2
@@ -98,7 +94,7 @@
9894
>>> thread.start()
9995
>>> thread.join()
10096
>>> log
101-
[[('color', 'red'), ('initialized', True)], 11]
97+
[[('color', 'red')], 11]
10298
10399
without affecting this thread's data:
104100

Lib/aifc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ def initfp(self, file):
308308
else:
309309
raise Error, 'not an AIFF or AIFF-C file'
310310
self._comm_chunk_read = 0
311+
self._ssnd_chunk = None
311312
while 1:
312313
self._ssnd_seek_needed = 1
313314
try:

Lib/difflib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ def _qformat(self, aline, bline, atags, btags):
11031103

11041104
import re
11051105

1106-
def IS_LINE_JUNK(line, pat=re.compile(r"\s*#?\s*$").match):
1106+
def IS_LINE_JUNK(line, pat=re.compile(r"\s*(?:#\s*)?$").match):
11071107
r"""
11081108
Return 1 for ignorable line: iff `line` is blank or contains a single '#'.
11091109

Lib/ensurepip/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
__all__ = ["version", "bootstrap"]
1313

1414

15-
_SETUPTOOLS_VERSION = "28.8.0"
15+
_SETUPTOOLS_VERSION = "39.0.1"
1616

17-
_PIP_VERSION = "9.0.1"
17+
_PIP_VERSION = "9.0.3"
1818

1919
_PROJECTS = [
2020
("setuptools", _SETUPTOOLS_VERSION),

Lib/fpformat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
__all__ = ["fix","sci","NotANumber"]
2020

2121
# Compiled regular expression to "decode" a number
22-
decoder = re.compile(r'^([-+]?)0*(\d*)((?:\.\d*)?)(([eE][-+]?\d+)?)$')
22+
decoder = re.compile(r'^([-+]?)(\d*)((?:\.\d*)?)(([eE][-+]?\d+)?)$')
2323
# \0 the whole thing
2424
# \1 leading sign or empty
2525
# \2 digits left of decimal point
@@ -41,6 +41,7 @@ def extract(s):
4141
res = decoder.match(s)
4242
if res is None: raise NotANumber, s
4343
sign, intpart, fraction, exppart = res.group(1,2,3,4)
44+
intpart = intpart.lstrip('0');
4445
if sign == '+': sign = ''
4546
if fraction: fraction = fraction[1:]
4647
if exppart: expo = int(exppart[1:])

Lib/poplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def rpop(self, user):
274274
return self._shortcmd('RPOP %s' % user)
275275

276276

277-
timestamp = re.compile(r'\+OK.*(<[^>]+>)')
277+
timestamp = re.compile(br'\+OK.[^<]*(<.*>)')
278278

279279
def apop(self, user, secret):
280280
"""Authorisation

Lib/test/support/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,14 @@ def temp_dir(path=None, quiet=False):
753753
raise
754754
warnings.warn('tests may fail, unable to create temp dir: ' + path,
755755
RuntimeWarning, stacklevel=3)
756+
if dir_created:
757+
pid = os.getpid()
756758
try:
757759
yield path
758760
finally:
759-
if dir_created:
761+
# In case the process forks, let only the parent remove the
762+
# directory. The child has a diffent process id. (bpo-30028)
763+
if dir_created and pid == os.getpid():
760764
rmtree(path)
761765

762766
@contextlib.contextmanager

Lib/test/test_aifc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ def test_read_no_comm_chunk(self):
214214
b = io.BytesIO('FORM' + struct.pack('>L', 4) + 'AIFF')
215215
self.assertRaises(aifc.Error, aifc.open, b)
216216

217+
def test_read_no_ssnd_chunk(self):
218+
b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
219+
b += b'COMM' + struct.pack('>LhlhhLL', 38, 0, 0, 0, 0, 0, 0)
220+
b += b'NONE' + struct.pack('B', 14) + b'not compressed' + b'\x00'
221+
with self.assertRaisesRegexp(aifc.Error, 'COMM chunk and/or SSND chunk'
222+
' missing'):
223+
aifc.open(io.BytesIO(b))
224+
217225
def test_read_wrong_compression_type(self):
218226
b = 'FORM' + struct.pack('>L', 4) + 'AIFC'
219227
b += 'COMM' + struct.pack('>LhlhhLL', 23, 0, 0, 0, 0, 0, 0)

Lib/test/test_dictviews.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import copy
22
import pickle
3+
import sys
34
import unittest
45
import collections
56
from test import test_support
@@ -169,6 +170,20 @@ def test_items_set_operations(self):
169170
def test_recursive_repr(self):
170171
d = {}
171172
d[42] = d.viewvalues()
173+
r = repr(d)
174+
# Cannot perform a stronger test, as the contents of the repr
175+
# are implementation-dependent. All we can say is that we
176+
# want a str result, not an exception of any sort.
177+
self.assertIsInstance(r, str)
178+
d[42] = d.viewitems()
179+
r = repr(d)
180+
# Again.
181+
self.assertIsInstance(r, str)
182+
183+
def test_deeply_nested_repr(self):
184+
d = {}
185+
for i in range(sys.getrecursionlimit() + 100):
186+
d = {42: d.viewvalues()}
172187
self.assertRaises(RuntimeError, repr, d)
173188

174189
def test_abc_registry(self):

Lib/test/test_difflib.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,33 @@ def test_range_format_context(self):
269269
self.assertEqual(fmt(3,6), '4,6')
270270
self.assertEqual(fmt(0,0), '0')
271271

272+
class TestJunkAPIs(unittest.TestCase):
273+
def test_is_line_junk_true(self):
274+
for line in ['#', ' ', ' #', '# ', ' # ', '']:
275+
self.assertTrue(difflib.IS_LINE_JUNK(line), repr(line))
276+
277+
def test_is_line_junk_false(self):
278+
for line in ['##', ' ##', '## ', 'abc ', 'abc #', 'Mr. Moose is up!']:
279+
self.assertFalse(difflib.IS_LINE_JUNK(line), repr(line))
280+
281+
def test_is_line_junk_REDOS(self):
282+
evil_input = ('\t' * 1000000) + '##'
283+
self.assertFalse(difflib.IS_LINE_JUNK(evil_input))
284+
285+
def test_is_character_junk_true(self):
286+
for char in [' ', '\t']:
287+
self.assertTrue(difflib.IS_CHARACTER_JUNK(char), repr(char))
288+
289+
def test_is_character_junk_false(self):
290+
for char in ['a', '#', '\n', '\f', '\r', '\v']:
291+
self.assertFalse(difflib.IS_CHARACTER_JUNK(char), repr(char))
272292

273293
def test_main():
274294
difflib.HtmlDiff._default_prefix = 0
275295
Doctests = doctest.DocTestSuite(difflib)
276296
run_unittest(
277297
TestWithAscii, TestAutojunk, TestSFpatches, TestSFbugs,
278-
TestOutputFormat, Doctests)
298+
TestOutputFormat, TestJunkAPIs)
279299

280300
if __name__ == '__main__':
281301
test_main()

Lib/test/test_fpformat.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ def test_failing_values(self):
6767
else:
6868
self.fail("No exception on non-numeric sci")
6969

70+
def test_REDOS(self):
71+
# This attack string will hang on the old decoder pattern.
72+
attack = '+0' + ('0' * 1000000) + '++'
73+
digs = 5 # irrelevant
74+
75+
# fix returns input if it does not decode
76+
self.assertEqual(fpformat.fix(attack, digs), attack)
77+
# sci raises NotANumber
78+
with self.assertRaises(NotANumber):
79+
fpformat.sci(attack, digs)
7080

7181
def test_main():
7282
run_unittest(FpformatTest)

Lib/test/test_ftplib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,11 +710,11 @@ def test_auth_ssl(self):
710710
self.client.auth()
711711
self.assertRaises(ValueError, self.client.auth)
712712
finally:
713-
self.client.ssl_version = ssl.PROTOCOL_TLSv1
713+
self.client.ssl_version = ssl.PROTOCOL_TLS
714714

715715
def test_context(self):
716716
self.client.quit()
717-
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
717+
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS)
718718
self.assertRaises(ValueError, ftplib.FTP_TLS, keyfile=CERTFILE,
719719
context=ctx)
720720
self.assertRaises(ValueError, ftplib.FTP_TLS, certfile=CERTFILE,
@@ -739,7 +739,7 @@ def test_context(self):
739739

740740
def test_check_hostname(self):
741741
self.client.quit()
742-
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
742+
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS)
743743
ctx.verify_mode = ssl.CERT_REQUIRED
744744
ctx.check_hostname = True
745745
ctx.load_verify_locations(CAFILE)

Lib/test/test_httplib.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ def test_networked_good_cert(self):
860860
import ssl
861861
test_support.requires('network')
862862
with test_support.transient_internet('self-signed.pythontest.net'):
863-
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
863+
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
864864
context.verify_mode = ssl.CERT_REQUIRED
865865
context.load_verify_locations(CERT_selfsigned_pythontestdotnet)
866866
h = httplib.HTTPSConnection('self-signed.pythontest.net', 443, context=context)
@@ -874,7 +874,7 @@ def test_networked_bad_cert(self):
874874
import ssl
875875
test_support.requires('network')
876876
with test_support.transient_internet('self-signed.pythontest.net'):
877-
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
877+
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
878878
context.verify_mode = ssl.CERT_REQUIRED
879879
context.load_verify_locations(CERT_localhost)
880880
h = httplib.HTTPSConnection('self-signed.pythontest.net', 443, context=context)
@@ -895,7 +895,7 @@ def test_local_good_hostname(self):
895895
# The (valid) cert validates the HTTP hostname
896896
import ssl
897897
server = self.make_server(CERT_localhost)
898-
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
898+
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
899899
context.verify_mode = ssl.CERT_REQUIRED
900900
context.load_verify_locations(CERT_localhost)
901901
h = httplib.HTTPSConnection('localhost', server.port, context=context)
@@ -907,7 +907,7 @@ def test_local_bad_hostname(self):
907907
# The (valid) cert doesn't validate the HTTP hostname
908908
import ssl
909909
server = self.make_server(CERT_fakehostname)
910-
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
910+
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
911911
context.verify_mode = ssl.CERT_REQUIRED
912912
context.check_hostname = True
913913
context.load_verify_locations(CERT_fakehostname)

Lib/test/test_ordered_dict.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,19 @@ def test_repr_recursive(self):
220220
self.assertEqual(repr(od),
221221
"OrderedDict([('a', None), ('b', None), ('c', None), ('x', ...)])")
222222

223+
def test_repr_recursive_values(self):
224+
od = OrderedDict()
225+
od[42] = od.viewvalues()
226+
r = repr(od)
227+
# Cannot perform a stronger test, as the contents of the repr
228+
# are implementation-dependent. All we can say is that we
229+
# want a str result, not an exception of any sort.
230+
self.assertIsInstance(r, str)
231+
od[42] = od.viewitems()
232+
r = repr(od)
233+
# Again.
234+
self.assertIsInstance(r, str)
235+
223236
def test_setdefault(self):
224237
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
225238
shuffle(pairs)

0 commit comments

Comments
 (0)