From 627af992fd4d7ba9d106461cc478eb14660e7ca5 Mon Sep 17 00:00:00 2001 From: Keshav Kini Date: Sat, 25 Feb 2012 00:15:46 +0800 Subject: 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. --- simplejson/encoder.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 -- cgit v1.2.1