summaryrefslogtreecommitdiff
path: root/Lib/json/encoder.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2011-03-16 18:27:34 -0400
committerR David Murray <rdmurray@bitdance.com>2011-03-16 18:27:34 -0400
commit676a72be33700a3df9f4930b7b080b800a93b011 (patch)
treeeeb73490e177be33ff1741b4ae6afcad190ff8ad /Lib/json/encoder.py
parenta6101cb3d1d6ebffa18cf7a784bdcaf98ee840d9 (diff)
parenta8ebdf3fd2c681864e0b6b0c6c4364cf6242904d (diff)
downloadcpython-676a72be33700a3df9f4930b7b080b800a93b011.tar.gz
Merge #11401 fix from 3.1.
Diffstat (limited to 'Lib/json/encoder.py')
-rw-r--r--Lib/json/encoder.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py
index 13359856d2..7475f5a544 100644
--- a/Lib/json/encoder.py
+++ b/Lib/json/encoder.py
@@ -259,6 +259,9 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
tuple=tuple,
):
+ if _indent is not None and not isinstance(_indent, str):
+ _indent = ' ' * _indent
+
def _iterencode_list(lst, _current_indent_level):
if not lst:
yield '[]'
@@ -271,7 +274,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
buf = '['
if _indent is not None:
_current_indent_level += 1
- newline_indent = '\n' + (' ' * (_indent * _current_indent_level))
+ newline_indent = '\n' + _indent * _current_indent_level
separator = _item_separator + newline_indent
buf += newline_indent
else:
@@ -307,7 +310,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
yield chunk
if newline_indent is not None:
_current_indent_level -= 1
- yield '\n' + (' ' * (_indent * _current_indent_level))
+ yield '\n' + _indent * _current_indent_level
yield ']'
if markers is not None:
del markers[markerid]
@@ -324,7 +327,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
yield '{'
if _indent is not None:
_current_indent_level += 1
- newline_indent = '\n' + (' ' * (_indent * _current_indent_level))
+ newline_indent = '\n' + _indent * _current_indent_level
item_separator = _item_separator + newline_indent
yield newline_indent
else:
@@ -383,7 +386,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
yield chunk
if newline_indent is not None:
_current_indent_level -= 1
- yield '\n' + (' ' * (_indent * _current_indent_level))
+ yield '\n' + _indent * _current_indent_level
yield '}'
if markers is not None:
del markers[markerid]