mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
Issue #5067: improve some json error messages.
Patch by Serhiy Storchaka.
This commit is contained in:
parent
24319ac407
commit
2d24e94bbe
5 changed files with 14 additions and 12 deletions
|
@ -173,7 +173,8 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook,
|
|||
pairs = object_hook(pairs)
|
||||
return pairs, end + 1
|
||||
elif nextchar != '"':
|
||||
raise ValueError(errmsg("Expecting property name", s, end))
|
||||
raise ValueError(errmsg(
|
||||
"Expecting property name enclosed in double quotes", s, end))
|
||||
end += 1
|
||||
while True:
|
||||
key, end = scanstring(s, end, strict)
|
||||
|
@ -183,7 +184,7 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook,
|
|||
if s[end:end + 1] != ':':
|
||||
end = _w(s, end).end()
|
||||
if s[end:end + 1] != ':':
|
||||
raise ValueError(errmsg("Expecting : delimiter", s, end))
|
||||
raise ValueError(errmsg("Expecting ':' delimiter", s, end))
|
||||
end += 1
|
||||
|
||||
try:
|
||||
|
@ -211,12 +212,13 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook,
|
|||
if nextchar == '}':
|
||||
break
|
||||
elif nextchar != ',':
|
||||
raise ValueError(errmsg("Expecting , delimiter", s, end - 1))
|
||||
raise ValueError(errmsg("Expecting ',' delimiter", s, end - 1))
|
||||
end = _w(s, end).end()
|
||||
nextchar = s[end:end + 1]
|
||||
end += 1
|
||||
if nextchar != '"':
|
||||
raise ValueError(errmsg("Expecting property name", s, end - 1))
|
||||
raise ValueError(errmsg(
|
||||
"Expecting property name enclosed in double quotes", s, end - 1))
|
||||
if object_pairs_hook is not None:
|
||||
result = object_pairs_hook(pairs)
|
||||
return result, end
|
||||
|
@ -250,7 +252,7 @@ def JSONArray(s_and_end, scan_once, _w=WHITESPACE.match, _ws=WHITESPACE_STR):
|
|||
if nextchar == ']':
|
||||
break
|
||||
elif nextchar != ',':
|
||||
raise ValueError(errmsg("Expecting , delimiter", s, end))
|
||||
raise ValueError(errmsg("Expecting ',' delimiter", s, end))
|
||||
try:
|
||||
if s[end] in _ws:
|
||||
end += 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue