summaryrefslogtreecommitdiff
path: root/gpscat
diff options
context:
space:
mode:
authorFred Wright <fw@fwright.net>2019-03-15 16:05:41 -0700
committerFred Wright <fw@fwright.net>2019-03-18 19:48:53 -0700
commite521c47ba41d4ebbe27883ab7807972109bf20cd (patch)
tree002d895cebccfdd306323e6366ba3f79c911a2a1 /gpscat
parent3d828ebdc1aeb9cb130b1bf02b1e81a1109a86af (diff)
downloadgpsd-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-xgpscat8
1 files changed, 5 insertions, 3 deletions
diff --git a/gpscat b/gpscat
index 9de1ba03..c48d6b9b 100755
--- a/gpscat
+++ b/gpscat
@@ -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