diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2011-01-29 06:41:17 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2011-01-29 06:41:17 -0500 |
commit | b111dbc2e989e2b8714f8c1ac49f8f6b26949588 (patch) | |
tree | 4703454ce779efe776289101b15c465a969bef1c /gps | |
parent | 24b81d753d98564767ce5af11ae5730791e4ab08 (diff) | |
download | gpsd-b111dbc2e989e2b8714f8c1ac49f8f6b26949588.tar.gz |
Catch and display regression errors from malformed JSON.
Diffstat (limited to 'gps')
-rw-r--r-- | gps/client.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/gps/client.py b/gps/client.py index b30ad858..541c5ae1 100644 --- a/gps/client.py +++ b/gps/client.py @@ -10,6 +10,11 @@ else: GPSD_PORT="2947" +class json_error: + def __init__(self, data, explanation): + self.data = data + self.explanation = explanation + class gpscommon: "Isolate socket handling and buffering from the protcol interpretation." def __init__(self, host="127.0.0.1", port=GPSD_PORT, verbose=0): @@ -142,7 +147,10 @@ class gpsjson(gpscommon): va = v t[ka] = va return t - self.data = dictwrapper(**asciify(json.loads(buf.strip(), encoding="ascii"))) + try: + self.data = dictwrapper(**asciify(json.loads(buf.strip(), encoding="ascii"))) + except ValueError, e: + raise json_error(buf, e.args[0]) # Should be done for any other array-valued subobjects, too. if self.data["class"] == "SKY" and hasattr(self.data, "satellites"): self.data.satellites = map(lambda x: dictwrapper(**x), self.data.satellites) |