summaryrefslogtreecommitdiff
path: root/gps/client.py
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-02-28 10:52:47 -0500
committerEric S. Raymond <esr@thyrsus.com>2011-02-28 10:52:47 -0500
commit593ea20df57e2c2195ac8ec1a4cd4580e0b60c22 (patch)
tree166159cdb4c0292145a7e748bc0dc6f202ac7831 /gps/client.py
parent4ac959a8f2782c237cfee159b7cee72e0db4cef2 (diff)
downloadgpsd-593ea20df57e2c2195ac8ec1a4cd4580e0b60c22.tar.gz
Abandon the attempt to de-Unicodify JSON as it comes in.
This turned out to cause mike_t's bug with doubling of backslashes - praobably doue to a subtle bug in the Python encode feature. And it seems not to be necessary, as Python doesn't notice the difference between plain and Unicode strings unless they contain Unicode. Has the nice effect of simplifying the Python client code. The only place decoding to ASCII is now done is where a C extension needs it.
Diffstat (limited to 'gps/client.py')
-rw-r--r--gps/client.py21
1 files changed, 3 insertions, 18 deletions
diff --git a/gps/client.py b/gps/client.py
index ef7a0b69..732da0f8 100644
--- a/gps/client.py
+++ b/gps/client.py
@@ -132,29 +132,14 @@ class gpsjson(gpscommon):
return self
def json_unpack(self, buf):
- def asciify(v):
- "De-Unicodify everything so we can copy dicts into Python objects."
- if type(v) == type(u"x"):
- return v.encode("ascii")
- elif type(v) == type({}):
- va = {}
- for (k, v) in v.items():
- ka = k.encode("ascii")
- kv = asciify(v)
- va[ka] = kv
- return va
- elif type(v) == type([]):
- return map(asciify, v)
- else:
- return v
try:
- self.data = dictwrapper(**asciify(json.loads(buf.strip(), encoding="ascii")))
+ self.data = dictwrapper(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.
# This particular logic can fire on SKY or RTCM2 objects.
if hasattr(self.data, "satellites"):
- self.data.satellites = map(lambda x: dictwrapper(**x), self.data.satellites)
+ self.data.satellites = map(lambda x: dictwrapper(x), self.data.satellites)
def stream(self, flags=0, outfile=None):
"Control streaming reports from the daemon,"
@@ -192,7 +177,7 @@ class gpsjson(gpscommon):
class dictwrapper:
"Wrapper that yields both class and dictionary behavior,"
- def __init__(self, **ddict):
+ def __init__(self, ddict):
self.__dict__ = ddict
def get(self, k, d=None):
return self.__dict__.get(k, d)