5 from _json
import make_scanner
as c_make_scanner
9 __all__
= ['make_scanner']
11 NUMBER_RE
= re
.compile(
12 r
'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?',
13 (re
.VERBOSE | re
.MULTILINE | re
.DOTALL
))
15 def py_make_scanner(context
):
16 parse_object
= context
.parse_object
17 parse_array
= context
.parse_array
18 parse_string
= context
.parse_string
19 match_number
= NUMBER_RE
.match
20 encoding
= context
.encoding
21 strict
= context
.strict
22 parse_float
= context
.parse_float
23 parse_int
= context
.parse_int
24 parse_constant
= context
.parse_constant
25 object_hook
= context
.object_hook
26 object_pairs_hook
= context
.object_pairs_hook
28 def _scan_once(string
, idx
):
30 nextchar
= string
[idx
]
35 return parse_string(string
, idx
+ 1, encoding
, strict
)
37 return parse_object((string
, idx
+ 1), encoding
, strict
,
38 _scan_once
, object_hook
, object_pairs_hook
)
40 return parse_array((string
, idx
+ 1), _scan_once
)
41 elif nextchar
== 'n' and string
[idx
:idx
+ 4] == 'null':
43 elif nextchar
== 't' and string
[idx
:idx
+ 4] == 'true':
45 elif nextchar
== 'f' and string
[idx
:idx
+ 5] == 'false':
48 m
= match_number(string
, idx
)
50 integer
, frac
, exp
= m
.groups()
52 res
= parse_float(integer
+ (frac
or '') + (exp
or ''))
54 res
= parse_int(integer
)
56 elif nextchar
== 'N' and string
[idx
:idx
+ 3] == 'NaN':
57 return parse_constant('NaN'), idx
+ 3
58 elif nextchar
== 'I' and string
[idx
:idx
+ 8] == 'Infinity':
59 return parse_constant('Infinity'), idx
+ 8
60 elif nextchar
== '-' and string
[idx
:idx
+ 9] == '-Infinity':
61 return parse_constant('-Infinity'), idx
+ 9
67 make_scanner
= c_make_scanner
or py_make_scanner