Merge #10019: Fix regression relative to 2.6: add newlines if indent=0
authorR David Murray <rdmurray@bitdance.com>
Wed, 13 Apr 2011 01:09:18 +0000 (21:09 -0400)
committerR David Murray <rdmurray@bitdance.com>
Wed, 13 Apr 2011 01:09:18 +0000 (21:09 -0400)
Patch by Amaury Forgeot d'Arc, updated by Sando Tosi.

1  2 
Doc/library/json.rst
Lib/json/encoder.py
Lib/test/json_tests/test_indent.py
Misc/NEWS

index 6bb7fe3a64082f2ba39194c9636b1abcba752825,2bf242fff42ba25ce99ba506bf7b17e920b495bc..9064409f983c4fc4e2c9c43a044c4c9161678d15
@@@ -134,12 -134,10 +134,12 @@@ Basic Usag
     ``inf``, ``-inf``) in strict compliance of the JSON specification, instead of
     using the JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
  
 -   If *indent* is a non-negative integer, then JSON array elements and object
 -   members will be pretty-printed with that indent level.  An indent level of 0,
 -   or negative, will only insert newlines.  ``None`` (the default) selects the
 -   most compact representation.
 +   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.  ``(',',
Simple merge
index d8030aaade1dc7c1cd24d016c0242c00ba394772,d45aa851bd755a90ef95664fd76451a476ad9341..692a494cfe5bfc84d1fc0d6164d1224209c29e8e
@@@ -40,6 -39,19 +41,21 @@@ class TestIndent(TestCase)
  
          self.assertEqual(h1, h)
          self.assertEqual(h2, h)
 -        self.assertEqual(d2, expect)
 +        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}')
diff --cc Misc/NEWS
Simple merge