From a7921275e20ff66724a64e99b83e0794bf43eb4e Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Thu, 7 Feb 2019 06:33:07 -0800 Subject: [PATCH] Use six where possible --- bin/weeutil/weeutil.py | 19 ++++--------------- bin/weewx/drivers/vantage.py | 4 +++- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/bin/weeutil/weeutil.py b/bin/weeutil/weeutil.py index 09cee55f..d117d11c 100644 --- a/bin/weeutil/weeutil.py +++ b/bin/weeutil/weeutil.py @@ -15,10 +15,12 @@ import calendar import datetime import math import os -import struct import syslog import time import traceback + +# Compatibility shims +import six from six.moves import StringIO # For backwards compatibility: @@ -1408,15 +1410,6 @@ def to_sorted_string(rec): return ", ".join(["%s: %s" % (k, rec.get(k)) for k in sorted(rec, key=str.lower)]) -# Define an "input" function that works for both Python 2 and 3: -# An exception will be raised in Python 3, but not Python 2 -try: - input = raw_input -except NameError: - # Python 3 - pass - - def y_or_n(msg, noprompt): """Prompt and look for a 'y' or 'n' response""" @@ -1426,14 +1419,10 @@ def y_or_n(msg, noprompt): ans = None while ans not in ['y', 'n']: - ans = input(msg) + ans = six.input(msg) return ans -def int2byte(x): - """Convert integer argument to signed byte string, under both Python 2 and 3""" - return struct.pack('>b', x) - if __name__ == '__main__': import doctest diff --git a/bin/weewx/drivers/vantage.py b/bin/weewx/drivers/vantage.py index 72580bc7..f393efda 100644 --- a/bin/weewx/drivers/vantage.py +++ b/bin/weewx/drivers/vantage.py @@ -14,8 +14,10 @@ import sys import syslog import time +from six import int2byte + from weewx.crc16 import crc16 -from weeutil.weeutil import to_int, int2byte +from weeutil.weeutil import to_int import weeutil.weeutil import weewx.drivers import weewx.units