"""JSON token scanner"""import retry:from _json import make_scanner as c_make_scannerexcept ImportError:c_make_scanner = None__all__ = ['make_scanner']NUMBER_RE = re.compile(r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?',(re.VERBOSE | re.MULTILINE | re.DOTALL))def py_make_scanner(context):parse_object = context.parse_objectparse_array = context.parse_arrayparse_string = context.parse_stringmatch_number = NUMBER_RE.matchstrict = context.strictparse_float = context.parse_floatparse_int = context.parse_intparse_constant = context.parse_constantobject_hook = context.object_hookobject_pairs_hook = context.object_pairs_hookmemo = context.memodef _scan_once(string, idx):try:nextchar = string[idx]except IndexError:raise StopIteration(idx) from Noneif nextchar == '"':return parse_string(string, idx + 1, strict)elif nextchar == '{':return parse_object((string, idx + 1), strict,_scan_once, object_hook, object_pairs_hook, memo)elif nextchar == '[':return parse_array((string, idx + 1), _scan_once)elif nextchar == 'n' and string[idx:idx + 4] == 'null':return None, idx + 4elif nextchar == 't' and string[idx:idx + 4] == 'true':return True, idx + 4elif nextchar == 'f' and string[idx:idx + 5] == 'false':return False, idx + 5m = match_number(string, idx)if m is not None:integer, frac, exp = m.groups()if frac or exp:res = parse_float(integer + (frac or '') + (exp or ''))else:res = parse_int(integer)return res, m.end()elif nextchar == 'N' and string[idx:idx + 3] == 'NaN':return parse_constant('NaN'), idx + 3elif nextchar == 'I' and string[idx:idx + 8] == 'Infinity':return parse_constant('Infinity'), idx + 8elif nextchar == '-' and string[idx:idx + 9] == '-Infinity':return parse_constant('-Infinity'), idx + 9else:raise StopIteration(idx)def scan_once(string, idx):try:return _scan_once(string, idx)finally:memo.clear()return scan_oncemake_scanner = c_make_scanner or py_make_scanner
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。