diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2010-04-18 20:26:09 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2010-04-18 20:26:09 -0400 |
commit | 262282ffbbfa1756de4fc7f2c6856a4663c907a1 (patch) | |
tree | a248b786b886ab253ba3244eadbd139e99ad2181 /gps | |
parent | 9c2b03f489e37d742527665adcc6ccb11716852c (diff) | |
download | gpsd-262282ffbbfa1756de4fc7f2c6856a4663c907a1.tar.gz |
Separate out common code a little better.
Diffstat (limited to 'gps')
-rwxr-xr-x | gps/gps.py | 45 |
1 files changed, 25 insertions, 20 deletions
@@ -119,6 +119,31 @@ class gpscommon: commands += "\n" self.sock.send(commands) +class dictwrapper: + "Wrapper that yields both class and dictionary behavior," + def __init__(self, **ddict): + self.__dict__ = ddict + def get(self, k, d=None): + return self.__dict__.get(k, d) + def keys(self): + return self.__dict__.keys() + def __getitem__(self, key): + "Emulate dictionary, for new-style interface." + return self.__dict__[key] + def __setitem__(self, key, val): + "Emulate dictionary, for new-style interface." + self.__dict__[key] = val + def __contains__(self, key): + return key in self.__dict__ + def __str__(self): + return "<dictwrapper: " + str(self.__dict__) + ">" + __repr__ = __str__ + + +# +# Stuff below this line is specific to the old interface +# + NaN = float('nan') def isnan(x): return str(x) == 'nan' @@ -262,26 +287,6 @@ class gpsdata: st += " %r\n" % sat return st -class dictwrapper: - "Wrapper that yields both class and dictionary behavior," - def __init__(self, **ddict): - self.__dict__ = ddict - def get(self, k, d=None): - return self.__dict__.get(k, d) - def keys(self): - return self.__dict__.keys() - def __getitem__(self, key): - "Emulate dictionary, for new-style interface." - return self.__dict__[key] - def __setitem__(self, key, val): - "Emulate dictionary, for new-style interface." - self.__dict__[key] = val - def __contains__(self, key): - return key in self.__dict__ - def __str__(self): - return "<dictwrapper: " + str(self.__dict__) + ">" - __repr__ = __str__ - class gps(gpsdata, gpscommon): "Client interface to a running gpsd instance." def __init__(self, host="127.0.0.1", port=GPSD_PORT, verbose=0, mode=0): |