4 from .errors
import JSONDecodeError
7 from ._speedups
import make_scanner
13 __all__ = [
'make_scanner',
'JSONDecodeError']
15 NUMBER_RE = re.compile(
16 r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?',
17 (re.VERBOSE | re.MULTILINE | re.DOTALL))
21 parse_object = context.parse_object
22 parse_array = context.parse_array
23 parse_string = context.parse_string
24 match_number = NUMBER_RE.match
25 encoding = context.encoding
26 strict = context.strict
27 parse_float = context.parse_float
28 parse_int = context.parse_int
29 parse_constant = context.parse_constant
30 object_hook = context.object_hook
31 object_pairs_hook = context.object_pairs_hook
34 def _scan_once(string, idx):
35 errmsg =
'Expecting value'
37 nextchar = string[idx]
42 return parse_string(string, idx + 1, encoding, strict)
44 return parse_object((string, idx + 1), encoding, strict,
45 _scan_once, object_hook, object_pairs_hook, memo)
47 return parse_array((string, idx + 1), _scan_once)
48 elif nextchar ==
'n' and string[idx:idx + 4] ==
'null':
50 elif nextchar ==
't' and string[idx:idx + 4] ==
'true':
52 elif nextchar ==
'f' and string[idx:idx + 5] ==
'false':
55 m = match_number(string, idx)
57 integer, frac, exp = m.groups()
59 res = parse_float(integer + (frac
or '') + (exp
or ''))
61 res = parse_int(integer)
63 elif nextchar ==
'N' and string[idx:idx + 3] ==
'NaN':
64 return parse_constant(
'NaN'), idx + 3
65 elif nextchar ==
'I' and string[idx:idx + 8] ==
'Infinity':
66 return parse_constant(
'Infinity'), idx + 8
67 elif nextchar ==
'-' and string[idx:idx + 9] ==
'-Infinity':
68 return parse_constant(
'-Infinity'), idx + 9
72 def scan_once(string, idx):
79 return _scan_once(string, idx)
85 make_scanner = c_make_scanner
or py_make_scanner