From 827150c07c6dc6b683c03cf2faf92e04dcada263 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 22 Feb 2011 13:54:25 -0500 Subject: Somewhat more effective asciifying in the Python client. --- gps/client.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'gps/client.py') 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: -- cgit v1.2.1