8000 merge · python/cpython@0e8c49d · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e8c49d

Browse files
committed
merge
2 parents 6a85f3c + 8ca705d commit 0e8c49d

File tree

23 files changed

+99
-42
lines changed

23 files changed

+99
-42
lines changed

Doc/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,15 @@ autobuild-dev:
187187
make update
188188
make dist SPHINXOPTS='-A daily=1 -A versionswitcher=1'
189189

190+
# for quick rebuilds (HTML only)
191+
autobuild-html:
192+
make html SPHINXOPTS='-A daily=1 -A versionswitcher=1'
193+
190194
# for stable releases: only build if not in pre-release stage (alpha, beta, rc)
191195
autobuild-stable:
192196
@case $(DISTVERSION) in *[abc]*) \
193197
echo "Not building; $(DISTVERSION) is not a release version."; \
194198
exit 1;; \
195199
esac
196200
@make autobuild-dev
201+

Doc/library/json.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ Using json.tool from the shell to validate and pretty-print::
116116
Basic Usage
117117
-----------
118118

119-
.. function:: dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, default=None, **kw)
119+
.. function:: dump(obj, fp, skipkeys=False, ensure_ascii=True, \
120+
check_circular=True, allow_nan=True, cls=None, \
121+
indent=None, separators=None, default=None, \
122+
sort_keys=False, **kw)
120123
121124
Serialize *obj* as a JSON formatted stream to *fp* (a ``.write()``-supporting
122125
:term:`file-like object`).
@@ -159,12 +162,18 @@ Basic Usage
159162
*default(obj)* is a function that should return a serializable version of
160163
*obj* or raise :exc:`TypeError`. The default simply raises :exc:`TypeError`.
161164

165+
If *sort_keys* is ``True`` (default: ``False``), then the output of
166+
dictionaries will be sorted by key.
167+
162168
To use a custom :class:`JSONEncoder` subclass (e.g. one that overrides the
163169
:meth:`default` method to serialize additional types), specify it with the
164170
*cls* kwarg; otherwise :class:`JSONEncoder` is used.
165171

166172

167-
.. function:: dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, default=None, **kw)
173+
.. function:: dumps(obj, skipkeys=False, ensure_ascii=True, \
174+
check_circular=True, allow_nan=True, cls=None, \
175+
indent=None, separators=None, default=None, \
176+
sort_keys=False, **kw)
168177
169178
Serialize *obj* to a JSON formatted :class:`str`. The arguments have the
170179
same meaning as in :func:`dump`.

Doc/library/shutil.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ Directory and files operations
7070
Now returns *dst*.
7171

7272
.. versionchanged:: 3.4
73-
Raise :exc:`SameFileError` instead of :exc:`Error`.
73+
Raise :exc:`SameFileError` instead of :exc:`Error`. Since the former is
74+
a subclass of the latter, this change is backward compatible.
7475

7576

7677
.. exception:: SameFileError

Doc/library/subprocess.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@ default values. The arguments that are most commonly needed are:
341341
from this vulnerability; see the Note in the :class:`Popen` constructor
342342
documentation for helpful hints in getting ``shell=False`` to work.
343343

344+
When using ``shell=True``, :func:`shlex.quote` can be used to properly
345+
escape whitespace and shell metacharacters in strings that are going to
346+
be used to construct shell commands.
347+
344348
These options, along with all of the other options, are described in more
345349
detail in the :class:`Popen` constructor documentation.
346350

Doc/tools/sphinxext/static/version_switch.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,21 @@
4343

4444
if (new_url != url) {
4545
// check beforehand if url exists, else redirect to version's start page
46-
$.get(new_url, function() {
47-
window.location.href = new_url;
48-
}).error(function() {
49-
window.location.href = 'http://docs.python.org/' + selected;
46+
$.ajax({
47+
url: new_url,
48+
success: function() {
49+
window.location.href = new_url;
50+
},
51+
error: function() {
52+
window.location.href = 'http://docs.python.org/' + selected;
53+
}
5054
});
5155
}
5256
}
5357

5458
$(document).ready(function() {
55-
var version = DOCUMENTATION_OPTIONS.VERSION.split('.'),
56-
release = DOCUMENTATION_OPTIONS.RELEASE || DOCUMENTATION_OPTIONS.VERSION;
57-
58-
version = version[0] + '.' + version[1];
59+
var release = DOCUMENTATION_OPTIONS.VERSION;
60+
var version = release.substr(0, 3);
5961
var select = build_select(version, release);
6062

6163
$('.version_switcher_placeholder').html(select);

Doc/whatsnew/2.6.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
.. XXX add trademark info for Apple, Microsoft, SourceForge.
88
99
:Author: A.M. Kuchling (amk at amk.ca)
10-
:Release: |release|
11-
:Date: |today|
1210

1311
.. $Id$
1412
Rules for maintenance:

Doc/whatsnew/2.7.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
****************************
44

55
:Author: A.M. Kuchling (amk at amk.ca)
6-
:Release: |release|
7-
:Date: |today|
86

97
.. hyperlink all the methods & functions.
108

Doc/whatsnew/3.0.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
.. XXX Add trademark info for Apple, Microsoft.
66
77
:Author: Guido van Rossum
8-
:Release: |release|
9-
:Date: |today|
108

119
.. $Id$
1210
Rules for maintenance:

Doc/whatsnew/3.1.rst

Copy file name to clipboard
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
****************************
44

55
:Author: Raymond Hettinger
6-
:Release: |release|
7-
:Date: |today|
86

97
.. $Id$
108
Rules for maintenance:

Doc/whatsnew/3.2.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
****************************
44

55
:Author: Raymond Hettinger
6-
:Release: |release|
7-
:Date: |today|
86

97
.. $Id$
108
Rules for maintenance:

Doc/whatsnew/3.3.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
What's New In Python 3.3
33
****************************
44

5-
:Release: |release|
6-
:Date: |today|
7-
85
.. Rules for maintenance:
96
107
* Anyone can add text to this document. Do not spend very much time

Doc/whatsnew/3.4.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
What's New In Python 3.4
33
****************************
44

5-
:Release: |release|
6-
:Date: |today|
5+
.. :Author: Someone <email>
6+
(uncomment if there is a principal author)
77
88
.. Rules for maintenance:
99

Include/pyport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
866866
#endif
867867

868868
/*
869-
* Convenient macros to deal with endianess of the platform. WORDS_BIGENDIAN is
869+
* Convenient macros to deal with endianness of the platform. WORDS_BIGENDIAN is
870870
* detected by configure and defined in pyconfig.h. The code in pyconfig.h
871871
* also also takes care of Apple's universal builds.
872872
*/

Lib/json/__init__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122

123123
def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
124124
allow_nan=True, cls=None, indent=None, separators=None,
125-
default=None, **kw):
125+
default=None, sort_keys=False, **kw):
126126
"""Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
127127
``.write()``-supporting file-like object).
128128
@@ -155,6 +155,9 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
155155
``default(obj)`` is a function that should return a serializable version
156156
of obj or raise TypeError. The default simply raises TypeError.
157157
158+
If *sort_keys* is ``True`` (default: ``False``), then the output of
159+
dictionaries will be sorted by key.
160+
158161
To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
159162
``.default()`` method to serialize additional types), specify it with
160163
the ``cls`` kwarg; otherwise ``JSONEncoder`` is used.
@@ -164,15 +167,15 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
164167
if (not skipkeys and ensure_ascii and
165168
check_circular and allow_nan and
166169
cls is None and indent is None and separators is None and
167-
default is None and not kw):
170+
default is None and not sort_keys and not kw):
168171
iterable = _default_encoder.iterencode(obj)
169172
else:
170173
if cls is None:
171174
cls = JSONEncoder
172175
iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
173176
check_circular=check_circular, allow_nan=allow_nan, indent=indent,
174177
separators=separators,
175-
default=default, **kw).iterencode(obj)
178+
default=default, sort_keys=sort_keys, **kw).iterencode(obj)
176179
# could accelerate with writelines in some versions of Python, at
177180
# a debuggability cost
178181
for chunk in iterable:
@@ -181,7 +184,7 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
181184

182185
def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
183186
allow_nan=True, cls=None, indent=None, separators=None,
184-
default=None, **kw):
187+
default=None, sort_keys=False, **kw):
185188
"""Serialize ``obj`` to a JSON formatted ``str``.
186189
187190
If ``skipkeys`` is false then ``dict`` keys that are not basic types
@@ -213,6 +216,9 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
213216
``default(obj)`` is a function that should return a serializable version
214217
of obj or raise TypeError. The default simply raises TypeError.
215218
219+
If *sort_keys* is ``True`` (default: ``False``), then the output of
220+
dictionaries will be sorted by key.
221+
216222
To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
217223
``.default()`` method to serialize additional types), specify it with
218224
the ``cls`` kwarg; otherwise ``JSONEncoder`` is used.
@@ -222,14 +228,14 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
222228
if (not skipkeys and ensure_ascii and
223229
check_circular and allow_nan and
224230
cls is None and indent is None and separators is None and
225-
default is None and not kw):
231+
default is None and not sort_keys and not kw):
226232
return _default_encoder.encode(obj)
227233
if cls is None:
228234
cls = JSONEncoder
229235
return cls(
230236
skipkeys=skipkeys, ensure_ascii=ensure_ascii,
231237
check_circular=check_circular, allow_nan=allow_nan, indent=indent,
232-
separators=separators, default=default,
238+
separators=separators, default=default, sort_keys=sort_keys,
233239
**kw).encode(obj)
234240

235241

Lib/mimetypes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,14 @@ def _default_mime_types():
378378
'.taz': '.tar.gz',
379379
'.tz': '.tar.gz',
380380
'.tbz2': '.tar.bz2',
381+
'.txz': '.tar.xz',
381382
}
382383

383384
encodings_map = {
384385
'.gz': 'gzip',
385386
'.Z': 'compress',
386387
'.bz2': 'bzip2',
388+
'.xz': 'xz',
387389
}
388390

389391
# Before adding new types, make sure they are either registered with IANA,

Lib/test/test_bz2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ def testEOFError(self):
640640
bz2d = BZ2Decompressor()
641641
text = bz2d.decompress(self.DATA)
642642
self.assertRaises(EOFError, bz2d.decompress, b"anything")
643+
self.assertRaises(EOFError, bz2d.decompress, b"")
643644

644645
@bigmemtest(size=_4G + 100, memuse=3)
645646
def testDecompress4G(self, size):

Lib/test/test_mimetypes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def test_default_data(self):
2222
eq(self.db.guess_type("foo.tgz"), ("application/x-tar", "gzip"))
2323
eq(self.db.guess_type("foo.tar.gz"), ("application/x-tar", "gzip"))
2424
eq(self.db.guess_type("foo.tar.Z"), ("application/x-tar", "compress"))
25+
eq(self.db.guess_type("foo.tar.bz2"), ("application/x-tar", "bzip2"))
26+
eq(self.db.guess_type("foo.tar.xz"), ("application/x-tar", "xz"))
2527

2628
def test_data_urls(self):
2729
eq = self.assertEqual

Lib/test/test_shutil.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,8 @@ def test_copyfile_same_file(self):
12231223
src_file = os.path.join(src_dir, 'foo')
12241224
write_file(src_file, 'foo')
12251225
self.assertRaises(SameFileError, shutil.copyfile, src_file, src_file)
1226+
# But Error should work too, to stay backward compatible.
1227+
self.assertRaises(Error, shutil.copyfile, src_file, src_file)
12261228

12271229
def test_copytree_return_value(self):
12281230
# copytree returns its destination path.

Lib/test/test_unicode.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,21 @@ def __format__(self, spec):
981981
self.assertRaises(ValueError, '{}'.format_map, 'a')
982982
self.assertRaises(ValueError, '{a} {}'.format_map, {"a" : 2, "b" : 1})
983983

984+
def test_format_huge_precision(self):
985+
format_string = ".{}f".format(sys.maxsize + 1)
986+
with self.assertRaises(ValueError):
987+
result = format(2.34, format_string)
988+
989+
def test_format_huge_width(self):
990+
format_string = "{}f".format(sys.maxsize + 1)
991+
with self.assertRaises(ValueError):
992+
result = format(2.34, format_string)
993+
994+
def test_format_huge_item_number(self):
995+
format_string = "{{{}:.6f}}".format(sys.maxsize + 1)
996+
with self.assertRaises(ValueError):
997+
result = format_string.format(2.34)
998+
984999
def test_format_auto_numbering(self):
9851000
class C:
9861001
def __init__(self, x=100):
@@ -1069,6 +1084,18 @@ def __str__(self):
10691084
self.assertEqual('%.1s' % "a\xe9\u20ac", 'a')
10701085
self.assertEqual('%.2s' % "a\xe9\u20ac", 'a\xe9')
10711086

1087+
@support.cpython_only
1088+
def test_formatting_huge_precision(self):
1089+
from _testcapi import INT_MAX
1090+
format_string = "%.{}f".format(INT_MAX + 1)
1091+
with self.assertRaises(ValueError):
1092+
result = format_string % 2.34
1093+
1094+
def test_formatting_huge_width(self):
1095+
format_string = "%{}f".format(sys.maxsize + 1)
1096+
with self.assertRaises(ValueError):
1097+
result = format_string % 2.34
1098+
10721099
def test_startswith_endswith_errors(self):
10731100
for meth in ('foo'.startswith, 'foo'.endswith):
10741101
with self.assertRaises(TypeError) as cm:

Lib/test/test_urllib2net.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ def test_file(self):
157157
## self._test_urls(urls, self._extra_handlers()+[bauth, dauth])
158158

159159
def test_urlwithfrag(self):
160-
urlwith_frag = "http://docs.python.org/glossary.html#glossary"
160+
urlwith_frag = "http://docs.python.org/2/glossary.html#glossary"
161161
with support.transient_internet(urlwith_frag):
162162
req = urllib.request.Request(urlwith_frag)
163163
res = urllib.request.urlopen(req)
164164
self.assertEqual(res.geturl(),
165-
"http://docs.python.org/glossary.html#glossary")
165+
"http://docs.python.org/2/glossary.html#glossary")
166166

167167
def test_custom_headers(self):
168168
url = "http://www.example.com"

Lib/venv/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,17 @@ def install_scripts(self, context, path):
313313
mode = 'wb'
314314
else:
315315
mode = 'w'
316-
data = data.decode('utf-8')
317-
data = self.replace_variables(data, context)
318-
with open(dstfile, mode) as f:
319-
f.write(data)
320-
shutil.copymode(srcfile, dstfile)
316+
try:
317+
data = data.decode('utf-8')
318+
data = self.replace_variables(data, context)
319+
except UnicodeDecodeError as e:
320+
data = None
321+
logger.warning('unable to copy script %r, '
322+
'may be binary: %s', srcfile, e)
323+
if data is not None:
324+
with open(dstfile, mode) as f:
325+
f.write(data)
326+
shutil.copymode(srcfile, dstfile)
321327

322328

323329
def create(env_dir, system_site_packages=False, clear=False, symlinks=False):

Misc/NEWS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Core and Builtins
2020
user that created them, even when the source file is read-only.
2121

2222
- Issue #16166: Add PY_LITTLE_ENDIAN and PY_BIG_ENDIAN macros and unified
23-
endianess detection and handling.
23+
endianness detection and handling.
2424

2525
- Issue #15958: bytes.join and bytearray.join now accept arbitrary buffer
2626
objects.
@@ -62,6 +62,9 @@ Core and Builtins
6262
Library
6363
-------
6464

65+
- Issue #16316: mimetypes now recognizes the .xz and .txz (.tar.xz) extensions.
66+
Patch by Serhiy Storchaka.
67+
6568
- Issue #12890: cgitb no longer prints spurious <p> tags in text
6669
mode when the logdir option is specified.
6770

Tools/msi/msi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def add_ui(db):
416416
("VerdanaRed9", "Verdana", 9, 255, 0),
417417
])
418418

419-
compileargs = r'-Wi "[TARGETDIR]Lib\compileall.py" -f -x "bad_coding|badsyntax|site-packages|py2_|lib2to3\\tests" "[TARGETDIR]Lib"'
419+
compileargs = r'-Wi "[TARGETDIR]Lib\compileall.py" -f -x "bad_coding|badsyntax|site-packages|py2_|lib2to3\\tests|venv\\scripts" "[TARGETDIR]Lib"'
420420
lib2to3args = r'-c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"'
421421
# See "CustomAction Table"
422422
add_data(db, "CustomAction", [

0 commit comments

Comments
 (0)
0