summaryrefslogtreecommitdiff
path: root/gps/client.py
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-02-22 13:54:25 -0500
committerEric S. Raymond <esr@thyrsus.com>2011-02-22 13:54:25 -0500
commit827150c07c6dc6b683c03cf2faf92e04dcada263 (patch)
tree8f659d08f6b15fade0bcf30e93a9533a2e30bd65 /gps/client.py
parentd220021b172c75b73561c31b248f1b3f77f63094 (diff)
downloadgpsd-827150c07c6dc6b683c03cf2faf92e04dcada263.tar.gz
Somewhat more effective asciifying in the Python client.
Diffstat (limited to 'gps/client.py')
-rw-r--r--gps/client.py28
1 files changed, 14 insertions, 14 deletions
diff --git a/gps/client.py b/gps/client.py
index 22503b13..ef7a0b69 100644
--- a/gps/client.py
+++ b/gps/client.py
@@ -132,21 +132,21 @@ class gpsjson(gpscommon):
return self
def json_unpack(self, buf):
- def asciify(d):
+ def asciify(v):
"De-Unicodify everything so we can copy dicts into Python objects."
- t = {}
- for (k, v) in d.items():
- ka = k.encode("ascii")
- if type(v) == type(u"x"):
- va = v.encode("ascii")
- elif type(v) == type({}):
- va = asciify(v)
- elif type(v) == type([]):
- va = map(asciify, v)
- else:
- va = v
- t[ka] = va
- return t
+ 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")))
except ValueError, e: