summaryrefslogtreecommitdiff
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
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.
-rw-r--r--gps/client.py21
-rwxr-xr-xgps/gps.py2
2 files changed, 4 insertions, 19 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)
diff --git a/gps/gps.py b/gps/gps.py
index 31f5a7a7..372293c9 100755
--- a/gps/gps.py
+++ b/gps/gps.py
@@ -262,7 +262,7 @@ class gps(gpsdata, gpsjson):
self.valid = ONLINE_SET
self.utc = default("time", None, TIME_SET)
if self.utc is not None:
- self.fix.time = isotime(self.utc)
+ self.fix.time = isotime(self.utc.encode("ascii"))
self.fix.ept = default("ept", NaN, TIMERR_SET)
self.fix.latitude = default("lat", NaN, LATLON_SET)
self.fix.longitude = default("lon", NaN)