summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2010-10-08 07:43:38 +0000
committerBob Ippolito <bob@redivi.com>2010-10-08 07:43:38 +0000
commitae8a27de9e8daef44d1542ec6425d19119b3ba17 (patch)
tree0788578c351d698d51edf58d7f8299a3a7435924
parent5075072f866a4ef098cc9ce4dd7f879fc040edcd (diff)
downloadsimplejson-ae8a27de9e8daef44d1542ec6425d19119b3ba17.tar.gz
http://bugs.python.org/issue10019
git-svn-id: http://simplejson.googlecode.com/svn/trunk@234 a4795897-2c25-0410-b006-0d3caba88fa1
-rw-r--r--CHANGES.txt2
-rw-r--r--simplejson/encoder.py4
-rw-r--r--simplejson/tests/test_indent.py16
3 files changed, 20 insertions, 2 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 31debb9..671a862 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,7 @@
Version 2.1.2 released XXXX-XX-XX
+* Correct output for indent=0
+ http://bugs.python.org/issue10019
* Correctly raise TypeError when non-string keys are used with speedups
http://code.google.com/p/simplejson/issues/detail?id=82
* Fix the endlineno, endcolno attributes of the JSONDecodeError exception.
diff --git a/simplejson/encoder.py b/simplejson/encoder.py
index cab8456..a7f4eea 100644
--- a/simplejson/encoder.py
+++ b/simplejson/encoder.py
@@ -147,7 +147,7 @@ class JSONEncoder(object):
If encoding is not None, then all input strings will be
transformed into unicode using that encoding prior to JSON-encoding.
The default is UTF-8.
-
+
If use_decimal is true (not the default), ``decimal.Decimal`` will
be supported directly by the encoder. For the inverse, decode JSON
with ``parse_float=decimal.Decimal``.
@@ -268,7 +268,7 @@ class JSONEncoder(object):
key_memo = {}
if (_one_shot and c_make_encoder is not None
- and not self.indent and not self.sort_keys):
+ and self.indent is None and not self.sort_keys):
_iterencode = c_make_encoder(
markers, self.default, _encoder, self.indent,
self.key_separator, self.item_separator, self.sort_keys,
diff --git a/simplejson/tests/test_indent.py b/simplejson/tests/test_indent.py
index 985831b..75a2f6e 100644
--- a/simplejson/tests/test_indent.py
+++ b/simplejson/tests/test_indent.py
@@ -2,6 +2,7 @@ from unittest import TestCase
import simplejson as json
import textwrap
+from StringIO import StringIO
class TestIndent(TestCase):
def test_indent(self):
@@ -51,3 +52,18 @@ class TestIndent(TestCase):
# so the following is expected to fail. Python 2.4 is not a
# supported platform in simplejson 2.1.0+.
self.assertEquals(d2, expect)
+
+ def test_indent0(self):
+ h = {3: 1}
+ def check(indent, expected):
+ d1 = json.dumps(h, indent=indent)
+ self.assertEquals(d1, expected)
+
+ sio = StringIO()
+ json.dump(h, sio, indent=indent)
+ self.assertEquals(sio.getvalue(), expected)
+
+ # indent=0 should emit newlines
+ check(0, '{\n"3": 1\n}')
+ # indent=None is more compact
+ check(None, '{"3": 1}')