mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Issue #5067: improve some json error messages.
Patch by Serhiy Storchaka.
This commit is contained in:
commit
802d669044
5 changed files with 14 additions and 12 deletions
|
|
@ -172,7 +172,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)
|
||||
|
|
@ -182,7 +183,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:
|
||||
|
|
@ -210,12 +211,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
|
||||
|
|
@ -249,7 +251,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