summaryrefslogtreecommitdiff
path: root/gpsfake
diff options
context:
space:
mode:
authorFred Wright <fw@fwright.net>2016-04-08 10:07:51 -0700
committerEric S. Raymond <esr@thyrsus.com>2016-04-09 04:39:16 -0400
commit62425c4eec4d5fc5ef353012fb7ef980425f16fa (patch)
tree2fd49fbdde82094f8a6ece7952ea818abcf98323 /gpsfake
parent79991ff14b9e396e319e108d7615d379163347d9 (diff)
downloadgpsd-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-xgpsfake8
1 files changed, 6 insertions, 2 deletions
diff --git a/gpsfake b/gpsfake
index 4be80470..f6874380 100755
--- a/gpsfake
+++ b/gpsfake
@@ -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