diff options
author | Fred Wright <fw@fwright.net> | 2016-04-08 10:07:51 -0700 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2016-04-09 04:39:16 -0400 |
commit | 62425c4eec4d5fc5ef353012fb7ef980425f16fa (patch) | |
tree | 2fd49fbdde82094f8a6ece7952ea818abcf98323 /gpsfake | |
parent | 79991ff14b9e396e319e108d7615d379163347d9 (diff) | |
download | gpsd-62425c4eec4d5fc5ef353012fb7ef980425f16fa.tar.gz |
Fixes fake.py and gpsfake for Python 3.
This incorporates the following changes:
1) Adds definitions for polystr(), polybytes(), and make_std_wrapper()
to misc.py (the most logical place for code needed by multiple
modules), using dummy definitions in the Python 2 case. For more
info, see the Practical Python Porting guide.
2) Reworks the logfile->daemon data path in fake.py to use 'bytes'
consistently.
3) Uses polybytes() in fake.py to construct control-socket commands as
'bytes', as expected by the socket I/O.
4) Uses make_std_wrapper() in gpsfake, to ensure that binary data is
correctly written to stdout.
5) Adds 'division' to the future imports in gpsfake for consistency,
though it doesn't actually matter in practice.
Also updates the compatibility comments in all three files, and fixes
a minor typo in misc.py.
TESTED:
Ran "scons build-all check" with Python 2.7, and ran all daemon
regression tests with Python 2.6 and with Python 3.2-3.5 (with
appropriately built extensions; not yet a build option).
Diffstat (limited to 'gpsfake')
-rwxr-xr-x | gpsfake | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -9,8 +9,9 @@ # This file is Copyright (c) 2010 by the GPSD project # BSD terms apply: see the file COPYING in the distribution root for details. -# This code runs under both Python 2 and Python 3. Preserve this property! -from __future__ import print_function +# This code runs compatibly under Python 2 and 3.x for x >= 2. +# Preserve this property! +from __future__ import print_function, division import getopt import gps @@ -27,6 +28,9 @@ try: except NameError: my_input = input +# Make sure stdout can accept binary data in Python 3 +sys.stdout = gps.make_std_wrapper(sys.stdout) + class Baton: "Ship progress indications to stderr." # By setting this > 1 we reduce the frequency of the twirl |