summaryrefslogtreecommitdiff
path: root/gpscap.py
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2016-03-22 03:08:21 -0400
committerEric S. Raymond <esr@thyrsus.com>2016-03-22 03:08:21 -0400
commit8200880a4949fd112674551374868f292b8a6524 (patch)
tree5332fe0413615a729c4953d43cba7a7ea7a1a17f /gpscap.py
parent254022f6c77e55280c6da59a01ee5225abdf7bcb (diff)
downloadgpsd-8200880a4949fd112674551374868f292b8a6524.tar.gz
Forward-port Python utilities to run polyglot under either Python 2 or 3.
For the moment most shebang lines still say 'python2' rather than just 'python'. This is because the client code in gps/ hasn't been touched yet; the internal imports break under Python 3 and that needs to be fixed.
Diffstat (limited to 'gpscap.py')
-rw-r--r--gpscap.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/gpscap.py b/gpscap.py
index 422ecb93..998d2f7a 100644
--- a/gpscap.py
+++ b/gpscap.py
@@ -1,17 +1,20 @@
"""
-
gpscap - GPS/AIS capability dictionary class.
This file is Copyright (c) 2010 by the GPSD project
BSD terms apply: see the file COPYING in the distribution root for details.
"""
-import ConfigParser
+from __future__ import print_function
+try:
+ import configparser
+except ImportError:
+ import ConfigParser as configparser
-class GPSDictionary(ConfigParser.RawConfigParser):
+class GPSDictionary(configparser.RawConfigParser):
def __init__(self, *files):
"Initialize the capability dictionary"
- ConfigParser.RawConfigParser.__init__(self)
+ configparser.RawConfigParser.__init__(self)
if not files:
files = ["gpscap.ini", "/usr/share/gpsd/gpscap.ini"]
self.read(files)
@@ -36,9 +39,9 @@ class GPSDictionary(ConfigParser.RawConfigParser):
# Sanity check: All items must have a type field.
for section in self.sections():
if not self.has_option(section, "type"):
- raise ConfigParser.Error("%s has no type" % section)
+ raise configparser.Error("%s has no type" % section)
elif self.get(section, "type") not in ("engine", "vendor", "device"):
- raise ConfigParser.Error("%s has invalid type" % section)
+ raise configparser.Error("%s has invalid type" % section)
# Sanity check: All devices must point at a vendor object.
# Side effect: build the lists of vendors and devices.
self.vendors = []
@@ -52,9 +55,9 @@ class GPSDictionary(ConfigParser.RawConfigParser):
for section in self.sections():
if self.get(section, "type") == "device":
if not self.has_option(section, "vendor"):
- raise ConfigParser.Error("%s has no vendor" % section)
+ raise configparser.Error("%s has no vendor" % section)
if self.get(section, "vendor") not in self.vendors:
- raise ConfigParser.Error("%s has invalid vendor" % section)
+ raise configparser.Error("%s has invalid vendor" % section)
def HTMLDump(self, ofp):
thead = """<table style='border:1px solid gray;font-size:small;background-color:#CCCCCC'>
@@ -167,6 +170,6 @@ if __name__ == "__main__":
try:
d = GPSDictionary()
d.HTMLDump(sys.stdout)
- except ConfigParser.Error, e:
- print >>sys.stderr, sys.argv[0]+":", e
- raise SystemExit, 1
+ except configparser.Error as e:
+ sys.stderr.write(sys.argv[0]+":%s\n" % e)
+ raise SystemExit(1)