*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)
| 340 | """ |
| 341 | |
| 342 | def __init__(self, encoding=None, object_hook=None, parse_float=None, |
| 343 | parse_int=None, parse_constant=None, strict=True, |
| 344 | object_pairs_hook=None): |
| 345 | """ |
| 346 | *encoding* determines the encoding used to interpret any |
| 347 | :class:`str` objects decoded by this instance (``'utf-8'`` by |
| 348 | default). It has no effect when decoding :class:`unicode` objects. |
| 349 | |
| 350 | Note that currently only encodings that are a superset of ASCII work, |
| 351 | strings of other encodings should be passed in as :class:`unicode`. |
| 352 | |
| 353 | *object_hook*, if specified, will be called with the result of every |
| 354 | JSON object decoded and its return value will be used in place of the |
| 355 | given :class:`dict`. This can be used to provide custom |
| 356 | deserializations (e.g. to support JSON-RPC class hinting). |
| 357 | |
| 358 | *object_pairs_hook* is an optional function that will be called with |
| 359 | the result of any object literal decode with an ordered list of pairs. |
| 360 | The return value of *object_pairs_hook* will be used instead of the |
| 361 | :class:`dict`. This feature can be used to implement custom decoders |
| 362 | that rely on the order that the key and value pairs are decoded (for |
| 363 | example, :func:`collections.OrderedDict` will remember the order of |
| 364 | insertion). If *object_hook* is also defined, the *object_pairs_hook* |
| 365 | takes priority. |
| 366 | |
| 367 | *parse_float*, if specified, will be called with the string of every |
| 368 | JSON float to be decoded. By default, this is equivalent to |
| 369 | ``float(num_str)``. This can be used to use another datatype or parser |
| 370 | for JSON floats (e.g. :class:`decimal.Decimal`). |
| 371 | |
| 372 | *parse_int*, if specified, will be called with the string of every |
| 373 | JSON int to be decoded. By default, this is equivalent to |
| 374 | ``int(num_str)``. This can be used to use another datatype or parser |
| 375 | for JSON integers (e.g. :class:`float`). |
| 376 | |
| 377 | *parse_constant*, if specified, will be called with one of the |
| 378 | following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This |
| 379 | can be used to raise an exception if invalid JSON numbers are |
| 380 | encountered. |
| 381 | |
| 382 | *strict* controls the parser's behavior when it encounters an |
| 383 | invalid control character in a string. The default setting of |
| 384 | ``True`` means that unescaped control characters are parse errors, if |
| 385 | ``False`` then control characters will be allowed in strings. |
| 386 | |
| 387 | """ |
| 388 | self.encoding = encoding |
| 389 | self.object_hook = object_hook |
| 390 | self.object_pairs_hook = object_pairs_hook |
| 391 | self.parse_float = parse_float or float |
| 392 | self.parse_int = parse_int or int |
| 393 | self.parse_constant = parse_constant or _CONSTANTS.__getitem__ |
| 394 | self.strict = strict |
| 395 | self.parse_object = JSONObject |
| 396 | self.parse_array = JSONArray |
| 397 | self.parse_string = scanstring |
| 398 | self.memo = {} |
| 399 | self.scan_once = make_scanner(self) |