[Python-checkins] cpython (2.7): Issue #5067: improve some json error messages.
antoine.pitrou
python-checkins at python.org
Fri Jun 29 02:03:52 CEST 2012
http://hg.python.org/cpython/rev/7762816e3fcd
changeset: 77842:7762816e3fcd
branch: 2.7
parent: 77838:49dee01d72f9
user: Antoine Pitrou <solipsis at pitrou.net>
date: Fri Jun 29 01:58:26 2012 +0200
summary:
Issue #5067: improve some json error messages.
Patch by Serhiy Storchaka.
files:
Doc/library/json.rst | 4 ++--
Lib/json/__init__.py | 2 +-
Lib/json/decoder.py | 15 +++++++--------
Lib/json/tool.py | 2 +-
Modules/_json.c | 8 ++++----
5 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/Doc/library/json.rst b/Doc/library/json.rst
--- a/Doc/library/json.rst
+++ b/Doc/library/json.rst
@@ -99,8 +99,8 @@
{
"json": "obj"
}
- $ echo '{ 1.2:3.4}' | python -mjson.tool
- Expecting property name: line 1 column 2 (char 2)
+ $ echo '{1.2:3.4}' | python -mjson.tool
+ Expecting property name enclosed in double quotes: line 1 column 1 (char 1)
.. highlight:: python
diff --git a/Lib/json/__init__.py b/Lib/json/__init__.py
--- a/Lib/json/__init__.py
+++ b/Lib/json/__init__.py
@@ -95,7 +95,7 @@
"json": "obj"
}
$ echo '{ 1.2:3.4}' | python -m json.tool
- Expecting property name: line 1 column 2 (char 2)
+ Expecting property name enclosed in double quotes: line 1 column 2 (char 2)
"""
__version__ = '2.0.9'
__all__ = [
diff --git a/Lib/json/decoder.py b/Lib/json/decoder.py
--- a/Lib/json/decoder.py
+++ b/Lib/json/decoder.py
@@ -169,7 +169,8 @@
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, encoding, strict)
@@ -179,8 +180,7 @@
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:
@@ -209,7 +209,7 @@
if nextchar == '}':
break
elif nextchar != ',':
- raise ValueError(errmsg("Expecting , delimiter", s, end - 1))
+ raise ValueError(errmsg("Expecting ',' delimiter", s, end - 1))
try:
nextchar = s[end]
@@ -224,8 +224,8 @@
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
@@ -259,8 +259,7 @@
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
diff --git a/Lib/json/tool.py b/Lib/json/tool.py
--- a/Lib/json/tool.py
+++ b/Lib/json/tool.py
@@ -7,7 +7,7 @@
"json": "obj"
}
$ echo '{ 1.2:3.4}' | python -m json.tool
- Expecting property name: line 1 column 2 (char 2)
+ Expecting property name enclosed in double quotes: line 1 column 2 (char 2)
"""
import sys
diff --git a/Modules/_json.c b/Modules/_json.c
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -1032,7 +1032,7 @@
while (idx <= end_idx) {
/* read key */
if (str[idx] != '"') {
- raise_errmsg("Expecting property name", pystr, idx);
+ raise_errmsg("Expecting property name enclosed in double quotes", pystr, idx);
goto bail;
}
key = scanstring_unicode(pystr, idx + 1, strict, &next_idx);
@@ -1043,7 +1043,7 @@
/* skip whitespace between key and : delimiter, read :, skip whitespace */
while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++;
if (idx > end_idx || str[idx] != ':') {
- raise_errmsg("Expecting : delimiter", pystr, idx);
+ raise_errmsg("Expecting ':' delimiter", pystr, idx);
goto bail;
}
idx++;
@@ -1075,7 +1075,7 @@
break;
}
else if (str[idx] != ',') {
- raise_errmsg("Expecting , delimiter", pystr, idx);
+ raise_errmsg("Expecting ',' delimiter", pystr, idx);
goto bail;
}
idx++;
@@ -1236,7 +1236,7 @@
break;
}
else if (str[idx] != ',') {
- raise_errmsg("Expecting , delimiter", pystr, idx);
+ raise_errmsg("Expecting ',' delimiter", pystr, idx);
goto bail;
}
idx++;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list