Use six where possible

This commit is contained in:
Tom Keffer
2019-02-07 06:33:07 -08:00
parent 7234f9bd04
commit a7921275e2
2 changed files with 7 additions and 16 deletions

View File

@@ -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

View File

@@ -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