MCPcopy Create free account
hub / github.com/simplejson/simplejson / __init__

Method __init__

simplejson/decoder.py:323–387  ·  view source on GitHub ↗

*encoding* determines the encoding used to interpret any :class:`str` objects decoded by this instance (``'utf-8'`` by default). It has no effect when decoding :class:`unicode` objects. Note that currently only encodings that are a superset of ASCII work, s

(self, encoding=None, object_hook=None, parse_float=None,
            parse_int=None, parse_constant=None, strict=True,
            object_pairs_hook=None, allow_nan=False,
            array_hook=None)

Source from the content-addressed store, hash-verified

321 """
322
323 def __init__(self, encoding=None, object_hook=None, parse_float=None,
324 parse_int=None, parse_constant=None, strict=True,
325 object_pairs_hook=None, allow_nan=False,
326 array_hook=None):
327 """
328 *encoding* determines the encoding used to interpret any
329 :class:`str` objects decoded by this instance (``'utf-8'`` by
330 default). It has no effect when decoding :class:`unicode` objects.
331
332 Note that currently only encodings that are a superset of ASCII work,
333 strings of other encodings should be passed in as :class:`unicode`.
334
335 *object_hook*, if specified, will be called with the result of every
336 JSON object decoded and its return value will be used in place of the
337 given :class:`dict`. This can be used to provide custom
338 deserializations (e.g. to support JSON-RPC class hinting).
339
340 *object_pairs_hook* is an optional function that will be called with
341 the result of any object literal decode with an ordered list of pairs.
342 The return value of *object_pairs_hook* will be used instead of the
343 :class:`dict`. This feature can be used to implement custom decoders
344 that rely on the order that the key and value pairs are decoded (for
345 example, :func:`collections.OrderedDict` will remember the order of
346 insertion). If *object_hook* is also defined, the *object_pairs_hook*
347 takes priority.
348
349 *parse_float*, if specified, will be called with the string of every
350 JSON float to be decoded. By default, this is equivalent to
351 ``float(num_str)``. This can be used to use another datatype or parser
352 for JSON floats (e.g. :class:`decimal.Decimal`).
353
354 *parse_int*, if specified, will be called with the string of every
355 JSON int to be decoded. By default, this is equivalent to
356 ``int(num_str)``. This can be used to use another datatype or parser
357 for JSON integers (e.g. :class:`float`).
358
359 *allow_nan*, if True (default false), will allow the parser to
360 accept the non-standard floats ``NaN``, ``Infinity``, and ``-Infinity``.
361
362 *parse_constant*, if specified, will be
363 called with one of the following strings: ``'-Infinity'``,
364 ``'Infinity'``, ``'NaN'``. It is not recommended to use this feature,
365 as it is rare to parse non-compliant JSON containing these values.
366
367 *strict* controls the parser's behavior when it encounters an
368 invalid control character in a string. The default setting of
369 ``True`` means that unescaped control characters are parse errors, if
370 ``False`` then control characters will be allowed in strings.
371
372 """
373 if encoding is None:
374 encoding = DEFAULT_ENCODING
375 self.encoding = encoding
376 self.object_hook = object_hook
377 self.object_pairs_hook = object_pairs_hook
378 self.parse_float = parse_float or float
379 self.parse_int = parse_int or bounded_int
380 self.parse_constant = parse_constant or (allow_nan and _CONSTANTS.__getitem__ or None)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected