summaryrefslogtreecommitdiff
path: root/jsongen.py.in
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 /jsongen.py.in
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 'jsongen.py.in')
-rw-r--r--jsongen.py.in32
1 files changed, 17 insertions, 15 deletions
diff --git a/jsongen.py.in b/jsongen.py.in
index 8155e43e..f3121de0 100644
--- a/jsongen.py.in
+++ b/jsongen.py.in
@@ -10,6 +10,8 @@
# This code generates template declarations for AIS-JSON parsing from a
# declarative specification of a JSON structure.
#
+from __future__ import print_function
+
import sys, getopt
#
@@ -934,9 +936,9 @@ def generate(spec):
attributes = [t[0] for t in spec["fieldmap"]]
for attr in spec.get("stringbuffered", []):
if attr not in attributes:
- print >>sys.stderr, "buffered %s is not in base attributes of %s"\
- % (attr, initname)
- raise SystemExit, 1
+ sys.stderr.write("buffered %s is not in base attributes of %s\n"
+ % (attr, initname))
+ raise SystemExit(1)
elif attr not in outboard:
report += " char %s[JSON_VAL_MAX+1];\n" % attr
outboard.append(attr)
@@ -958,8 +960,8 @@ def generate(spec):
elif default:
report += leader + ".len = %s},\n" % (default,)
else:
- print >>sys.stderr, "explicit length specification required"
- raise SystemExit, 1
+ sys.stderr.write("explicit length specification required\n")
+ raise SystemExit(1)
report += """\
{NULL}
};
@@ -999,7 +1001,7 @@ def generate(spec):
{NULL}
};
"""
- print report
+ print(report)
if __name__ == '__main__':
try:
@@ -1007,9 +1009,9 @@ if __name__ == '__main__':
# In the future, this script will generate more different kinds
# of code.
(options, arguments) = getopt.getopt(sys.argv[1:], "", ["ais", "target="])
- except getopt.GetoptError, msg:
- print "jsongen.py: " + str(msg)
- raise SystemExit, 1
+ except getopt.GetoptError as msg:
+ print("jsongen.py: " + str(msg))
+ raise SystemExit(1)
spec = None
target = None
@@ -1020,26 +1022,26 @@ if __name__ == '__main__':
target = val
if not target or not spec:
- print "jsongen.py: must specify type and target."
- raise SystemExit, 1
+ print("jsongen.py: must specify type and target.")
+ raise SystemExit(1)
if target == 'parser':
- print """/*
+ print("""/*
* This is code generated by jsongen.py. Do not hand-hack it!
*/
#define NITEMS(x) (int)(sizeof(x)/sizeof(x[0]))
/*@ -fullinitblock */
-"""
+""")
outboard = []
for description in spec:
generate(description)
- print """
+ print("""
/*@ +fullinitblock */
/* Generated code ends. */
-"""
+""")
# The following sets edit modes for GNU EMACS
# Local Variables:
# mode:python