From 6005fde964ba8abfe48160c36b224dadd2bdc741 Mon Sep 17 00:00:00 2001 From: Fred Wright Date: Sun, 10 Apr 2016 19:29:06 -0700 Subject: Fixes Python programs to use new-style classes. Although this isn't strictly a Python 3 requirement, using the new-style class definition syntax improves consistency between Python 2 and Python 3. Old-style classes have been deprecated since Python 2.2, but many such definitions linger on. Python 3 eliminates old-style classes, but instead of complaining about old-style definitions, it simply unconditionally and silently makes all classes new-style. The only incompatible differences are quite subtle and rarely matter in practice, but things are more consistent across versions if the new-style definitions are used. Also, the preferred method for subclasses to invoke parent init methods is via the super() construct, which is only available with new-style classes. Using super() is especially useful with multiple inheritance, which it handles automatically (provided that the init methods have compatible signatures). TESTED: Using an SConstruct patched to run the build helpers with the target Python, ran "scons build-all check ", as well as gpsprof and xgps, with all six supported Python versions (except 2.6 for xgps). --- gpsfake | 2 +- gpsprof | 4 ++-- gpssim.py | 8 ++++---- maskaudit.py | 3 ++- xgps | 10 +++++----- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/gpsfake b/gpsfake index 9a3f6f30..28e86c88 100755 --- a/gpsfake +++ b/gpsfake @@ -31,7 +31,7 @@ except NameError: # Make sure stdout can accept binary data in Python 3 sys.stdout = gps.make_std_wrapper(sys.stdout) -class Baton: +class Baton(object): "Ship progress indications to stderr." # By setting this > 1 we reduce the frequency of the twirl # and speed up test runs. Should be relatively prime to the diff --git a/gpsprof b/gpsprof index 5c9c52d6..d0aad600 100755 --- a/gpsprof +++ b/gpsprof @@ -21,7 +21,7 @@ import sys import time -class Baton: +class Baton(object): "Ship progress indication to stderr." def __init__(self, prompt, endmsg=None): @@ -55,7 +55,7 @@ class Baton: return -class plotter: +class plotter(object): "Generic class for gathering and plotting sensor statistics." def __init__(self): diff --git a/gpssim.py b/gpssim.py index fb686e67..69c3da17 100644 --- a/gpssim.py +++ b/gpssim.py @@ -12,7 +12,7 @@ import gps, gpslib # and a satellite with specified orbital elements in the sky. -class ksv: +class ksv(object): "Kinematic state vector." def __init__(self, time=0, lat=0, lon=0, alt=0, course=0, @@ -61,7 +61,7 @@ class ksv: # -class satellite: +class satellite(object): "Orbital elements of one satellite. PRESENTLY A STUB" def __init__(self, prn): @@ -88,7 +88,7 @@ class gpssimException(BaseException): return '"%s", %d:' % (self.filename, self.lineno) -class gpssim: +class gpssim(object): "Simulate a moving sensor, with skyview." active_PRNs = list(range(1, 24 + 1)) + [134, ] @@ -186,7 +186,7 @@ class gpssim: MPS_TO_KNOTS = 1.9438445 # Meters per second to knots -class NMEA: +class NMEA(object): "NMEA output generator." def __init__(self): diff --git a/maskaudit.py b/maskaudit.py index 20bc5d0a..48058098 100755 --- a/maskaudit.py +++ b/maskaudit.py @@ -22,7 +22,8 @@ try: except ImportError: from commands import getstatusoutput -class SourceExtractor: + +class SourceExtractor(object): def __init__(self, sourcefile, clientside): self.sourcefile = sourcefile self.clientside = clientside diff --git a/xgps b/xgps index 2646e5f7..4a0abbe6 100755 --- a/xgps +++ b/xgps @@ -40,7 +40,7 @@ import gps.clienthelpers SKY_VIEW_SORT_FIELDS = ('-used', 'PRN') -class unit_adjustments: +class unit_adjustments(object): "Encapsulate adjustments for unit systems." def __init__(self, units=None): @@ -262,7 +262,7 @@ class SkyView(Gtk.DrawingArea): self.queue_draw() -class NoiseView: +class NoiseView(object): "Encapsulate view object for watching noise statistics." COLUMNS = 2 ROWS = 4 @@ -308,7 +308,7 @@ class NoiseView: widget.set_text("n/a") -class MaidenheadView: +class MaidenheadView(object): "Encapsulate view object for watching Maidenhead grid location." def __init__(self): @@ -322,7 +322,7 @@ class MaidenheadView: return self.widget.set_text("n/a") -class AISView: +class AISView(object): "Encapsulate store and view objects for watching AIS data." AIS_ENTRIES = 10 DWELLTIME = 360 @@ -436,7 +436,7 @@ class AISView: (ais.type, ais.name, "(%s navaid)" % ais.epfd_text, "", where, ais.aid_type_text)) -class Base: +class Base(object): COLUMNS = 3 ROWS = 7 gpsfields = ( -- cgit v1.2.1