6 __author__ =
'CACode <cacode@163.com>'
8 from .
import _default_encoder, JSONEncoder, _default_decoder, JSONDecoder
9 from decimal
import Decimal
15 def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
16 allow_nan=True, cls=None, indent=None, separators=None,
17 encoding='utf-8', default=None, use_decimal=True,
18 namedtuple_as_object=True, tuple_as_array=True,
19 bigint_as_string=False, sort_keys=False, item_sort_key=None,
20 for_json=False, ignore_nan=False, int_as_string_bitcount=None,
21 iterable_as_array=False, **kw):
25 if (
not skipkeys
and ensure_ascii
and
26 check_circular
and allow_nan
and
27 cls
is None and indent
is None and separators
is None and
28 encoding ==
'utf-8' and default
is None and use_decimal
29 and namedtuple_as_object
and tuple_as_array
and not iterable_as_array
30 and not bigint_as_string
and not sort_keys
31 and not item_sort_key
and not for_json
32 and not ignore_nan
and int_as_string_bitcount
is None
35 return _default_encoder.encode(obj)
39 skipkeys=skipkeys, ensure_ascii=ensure_ascii,
40 check_circular=check_circular, allow_nan=allow_nan, indent=indent,
41 separators=separators, encoding=encoding, default=default,
42 use_decimal=use_decimal,
43 namedtuple_as_object=namedtuple_as_object,
44 tuple_as_array=tuple_as_array,
45 iterable_as_array=iterable_as_array,
46 bigint_as_string=bigint_as_string,
48 item_sort_key=item_sort_key,
50 ignore_nan=ignore_nan,
51 int_as_string_bitcount=int_as_string_bitcount,
55 def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
56 parse_int=None, parse_constant=None, object_pairs_hook=None,
57 use_decimal=False, **kw):
61 if (cls
is None and encoding
is None and object_hook
is None and
62 parse_int
is None and parse_float
is None and
63 parse_constant
is None and object_pairs_hook
is None
64 and not use_decimal
and not kw):
65 return _default_decoder.decode(s)
68 if object_hook
is not None:
69 kw[
'object_hook'] = object_hook
70 if object_pairs_hook
is not None:
71 kw[
'object_pairs_hook'] = object_pairs_hook
72 if parse_float
is not None:
73 kw[
'parse_float'] = parse_float
74 if parse_int
is not None:
75 kw[
'parse_int'] = parse_int
76 if parse_constant
is not None:
77 kw[
'parse_constant'] = parse_constant
79 if parse_float
is not None:
80 raise TypeError(
"use_decimal=True implies parse_float=Decimal")
81 kw[
'parse_float'] = Decimal
82 return cls(encoding=encoding, **kw).decode(s)