this repo has no description
at trunk 65 lines 1.8 kB view raw
1# Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) 2from _builtins import _builtin 3 4 5class JSONDecodeError(ValueError): 6 """Subclass of ValueError with the following additional properties: 7 8 msg: The unformatted error message 9 doc: The JSON document being parsed 10 pos: The start index of doc where parsing failed 11 lineno: The line corresponding to pos 12 colno: The column corresponding to pos 13 14 """ 15 16 # Note that this exception is used from _json 17 def __init__(self, msg, doc, pos): 18 lineno = doc.count("\n", 0, pos) + 1 19 colno = pos - doc.rfind("\n", 0, pos) 20 errmsg = f"{msg}: line {lineno} column {colno} (char {pos})" 21 super().__init__(errmsg) 22 self.msg = msg 23 self.doc = doc 24 self.pos = pos 25 self.lineno = lineno 26 self.colno = colno 27 28 def __reduce__(self): 29 return self.__class__, (self.msg, self.doc, self.pos) 30 31 32def _decode_with_cls( 33 s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw 34): 35 if cls is None: 36 cls = _JSONDecoder 37 if object_hook is not None: 38 kw["object_hook"] = object_hook 39 if object_pairs_hook is not None: 40 kw["object_pairs_hook"] = object_pairs_hook 41 if parse_float is not None: 42 kw["parse_float"] = parse_float 43 if parse_int is not None: 44 kw["parse_int"] = parse_int 45 if parse_constant is not None: 46 kw["parse_constant"] = parse_constant 47 return cls(**kw).decode(s) 48 49 50def loads( 51 s, 52 *, 53 encoding=None, 54 cls=None, 55 object_hook=None, 56 parse_float=None, 57 parse_int=None, 58 parse_constant=None, 59 object_pairs_hook=None, 60 **kw, 61): 62 _builtin() 63 64 65from json.decoder import JSONDecoder as _JSONDecoder