summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeshav Kini <keshav.kini@gmail.com>2012-02-25 00:15:46 +0800
committerKeshav Kini <keshav.kini@gmail.com>2012-02-25 00:32:34 +0800
commit627af992fd4d7ba9d106461cc478eb14660e7ca5 (patch)
treee8aa6c8509e04da44d813834b3b8bb953c261857
parentf9f73115e42bcda4526cc89f145c873c7be2bef6 (diff)
downloadsimplejson-627af992fd4d7ba9d106461cc478eb14660e7ca5.tar.gz
Allow unknown numerical types for indent parameter
This was causing failures in software which passes objects which are neither of type str, int, or long, but rather a custom numerical class, as the value of the indent parameter. Since this custom numerical class understands multiplication by strings, it should be accepted by simplejson's encoder and treated as a numerical argument.
-rw-r--r--simplejson/encoder.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/simplejson/encoder.py b/simplejson/encoder.py
index 8a26141..17c8fbb 100644
--- a/simplejson/encoder.py
+++ b/simplejson/encoder.py
@@ -170,8 +170,10 @@ class JSONEncoder(object):
self.use_decimal = use_decimal
self.namedtuple_as_object = namedtuple_as_object
self.tuple_as_array = tuple_as_array
- if isinstance(indent, (int, long)):
+ try:
indent = ' ' * indent
+ except TypeError:
+ pass
self.indent = indent
if separators is not None:
self.item_separator, self.key_separator = separators