diff options
author | Senthil Kumaran <orsenthil@gmail.com> | 2011-04-13 01:34:21 (GMT) |
---|---|---|
committer | Senthil Kumaran <orsenthil@gmail.com> | 2011-04-13 01:34:21 (GMT) |
commit | af87886d8dd0cab6f06b4721540f2a64f36676b6 (patch) | |
tree | 20d9c05962aeea37ce298dc7ae92758a7f5b85fa | |
parent | 6dc605735d26230e3c5ebf79db8637bb041e9ee0 (diff) | |
parent | d5315482e92d1f3c47460999a790df684bf8b09e (diff) | |
download | cpython-af87886d8dd0cab6f06b4721540f2a64f36676b6.zip cpython-af87886d8dd0cab6f06b4721540f2a64f36676b6.tar.gz cpython-af87886d8dd0cab6f06b4721540f2a64f36676b6.tar.bz2 |
merge update
-rw-r--r-- | Doc/library/json.rst | 8 | ||||
-rw-r--r-- | Lib/json/encoder.py | 2 | ||||
-rw-r--r-- | Lib/test/json_tests/test_indent.py | 16 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
4 files changed, 24 insertions, 5 deletions
diff --git a/Doc/library/json.rst b/Doc/library/json.rst index 6bb7fe3..9064409 100644 --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -136,10 +136,10 @@ Basic Usage If *indent* is a non-negative integer or string, then JSON array elements and object members will be pretty-printed with that indent level. An indent level - of 0 or ``""`` will only insert newlines. ``None`` (the default) selects the - most compact representation. Using an integer indent indents that many spaces - per level. If *indent* is a string (such at '\t'), that string is used to indent - each level. + of 0, negative, or ``""`` will only insert newlines. ``None`` (the default) + selects the most compact representation. Using a positive integer indent + indents that many spaces per level. If *indent* is a string (such at '\t'), + that string is used to indent each level. If *separators* is an ``(item_separator, dict_separator)`` tuple, then it will be used instead of the default ``(', ', ': ')`` separators. ``(',', diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py index 7475f5a..4b214eb 100644 --- a/Lib/json/encoder.py +++ b/Lib/json/encoder.py @@ -233,7 +233,7 @@ class JSONEncoder(object): if (_one_shot and c_make_encoder is not None - and not self.indent): + and self.indent is None): _iterencode = c_make_encoder( markers, self.default, _encoder, self.indent, self.key_separator, self.item_separator, self.sort_keys, diff --git a/Lib/test/json_tests/test_indent.py b/Lib/test/json_tests/test_indent.py index d8030aa..692a494 100644 --- a/Lib/test/json_tests/test_indent.py +++ b/Lib/test/json_tests/test_indent.py @@ -2,6 +2,7 @@ from unittest import TestCase import json import textwrap +from io import StringIO class TestIndent(TestCase): def test_indent(self): @@ -43,3 +44,18 @@ class TestIndent(TestCase): self.assertEqual(h3, h) self.assertEqual(d2, expect.expandtabs(2)) self.assertEqual(d3, expect) + + def test_indent0(self): + h = {3: 1} + def check(indent, expected): + d1 = json.dumps(h, indent=indent) + self.assertEqual(d1, expected) + + sio = StringIO() + json.dump(h, sio, indent=indent) + self.assertEqual(sio.getvalue(), expected) + + # indent=0 should emit newlines + check(0, '{\n"3": 1\n}') + # indent=None is more compact + check(None, '{"3": 1}') @@ -55,6 +55,9 @@ Library - Issue #11703 - urllib2.geturl() does not return correct url when the original url contains #fragment. + +- Issue #10019: Fixed regression in json module where an indent of 0 stopped + adding newlines and acted instead like 'None'. - Issue #5162: Treat services like frozen executables to allow child spawning from multiprocessing.forking on Windows. |