summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2011-04-12 11:29:46 -0700
committerBob Ippolito <bob@redivi.com>2011-04-12 11:29:46 -0700
commit5cad556f7d60a84eda51adca054c51a192c98c09 (patch)
tree83bba7e62a21a7c54dcaf84eddd08c616c131ebf
parent1a371353a0fdf324f4b98c9f3e13439724066655 (diff)
downloadsimplejson-5cad556f7d60a84eda51adca054c51a192c98c09.tar.gz
Trailing whitespace after commas no longer emitted when indent is used
-rw-r--r--CHANGES.txt1
-rw-r--r--simplejson/encoder.py2
-rw-r--r--simplejson/tests/test_indent.py17
3 files changed, 20 insertions, 0 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index c54f2e2..1a3631d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,6 @@
Version 2.1.4 released XXXX-XX-XX
+* Trailing whitespace after commas no longer emitted when indent is used
* Migrated to github http://github.com/simplejson/simplejson
Version 2.1.3 released 2011-01-17
diff --git a/simplejson/encoder.py b/simplejson/encoder.py
index 468d1bd..f43f6f4 100644
--- a/simplejson/encoder.py
+++ b/simplejson/encoder.py
@@ -165,6 +165,8 @@ class JSONEncoder(object):
self.indent = indent
if separators is not None:
self.item_separator, self.key_separator = separators
+ elif indent is not None:
+ self.item_separator = ','
if default is not None:
self.default = default
self.encoding = encoding
diff --git a/simplejson/tests/test_indent.py b/simplejson/tests/test_indent.py
index 75a2f6e..1e6bdb1 100644
--- a/simplejson/tests/test_indent.py
+++ b/simplejson/tests/test_indent.py
@@ -67,3 +67,20 @@ class TestIndent(TestCase):
check(0, '{\n"3": 1\n}')
# indent=None is more compact
check(None, '{"3": 1}')
+
+ def test_separators(self):
+ lst = [1,2,3,4]
+ expect = '[\n1,\n2,\n3,\n4\n]'
+ expect_spaces = '[\n1, \n2, \n3, \n4\n]'
+ # Ensure that separators still works
+ self.assertEquals(
+ expect_spaces,
+ json.dumps(lst, indent=0, separators=(', ', ': ')))
+ # Force the new defaults
+ self.assertEquals(
+ expect,
+ json.dumps(lst, indent=0, separators=(',', ': ')))
+ # Added in 2.1.4
+ self.assertEquals(
+ expect,
+ json.dumps(lst, indent=0)) \ No newline at end of file