diff options
author | Fred Wright <fw@fwright.net> | 2019-03-15 16:05:41 -0700 |
---|---|---|
committer | Fred Wright <fw@fwright.net> | 2019-03-18 19:48:53 -0700 |
commit | e521c47ba41d4ebbe27883ab7807972109bf20cd (patch) | |
tree | 002d895cebccfdd306323e6366ba3f79c911a2a1 /gpscat | |
parent | 3d828ebdc1aeb9cb130b1bf02b1e81a1109a86af (diff) | |
download | gpsd-e521c47ba41d4ebbe27883ab7807972109bf20cd.tar.gz |
gpscat: Fix for Python without curses package.
Some Python installs (notably some NetBSD versions) lack the curses
package. Since its only use here was for the printable character test,
derive a test from string.printable instead.
TESTED:
Tested (in raw mode) with a receiver mixing NMEA and binary, with
Python 2.6, 2.7, and 3.2-3.7, observing proper printability filtering.
Diffstat (limited to 'gpscat')
-rwxr-xr-x | gpscat | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -13,15 +13,15 @@ import getopt import os import select import socket +import string import sys import termios -import curses.ascii - # pylint wants local modules last try: import gps import gps.packet as sniffer + from gps.misc import BINARY_ENCODING except ImportError as e: sys.stderr.write( "gpscat: can't load Python gps libraries -- check PYTHONPATH.\n") @@ -44,12 +44,14 @@ BASELEVEL = sniffer.LOG_IO highhalf_latch = True +PRINTABLE = set(bytearray(string.printable, encoding=BINARY_ENCODING)) + def hexdump(st): "Convert string to hex string" dmp = "" for ch in bytearray(st): # bytearray gets array of ints in Python 2 and 3 - if curses.ascii.isprint(ch) or curses.ascii.isspace(ch): + if ch in PRINTABLE: dmp += chr(ch) else: dmp += "\\x%02x" % ch |