Python3 compatibility for hidconsole
`type(u'')` is 'str' in Python 3, it was `unicode` on Python 2 (with `unicode_literals` from `__future__`).
This commit is contained in:
parent
0f80901bce
commit
a6b89b3ea3
|
@ -15,12 +15,17 @@ import hidapi
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
# no Python 3 support :(
|
try:
|
||||||
read_packet = raw_input
|
read_packet = raw_input
|
||||||
|
except NameError:
|
||||||
|
# Python 3 equivalent of raw_input
|
||||||
|
read_packet = input
|
||||||
|
|
||||||
interactive = os.isatty(0)
|
interactive = os.isatty(0)
|
||||||
prompt = '?? Input: ' if interactive else ''
|
prompt = '?? Input: ' if interactive else ''
|
||||||
|
|
||||||
strhex = lambda d: hexlify(d).decode('ascii').upper()
|
strhex = lambda d: hexlify(d).decode('ascii').upper()
|
||||||
|
is_string = lambda d: type(d) == (str if type(u'') == str else unicode)
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -33,7 +38,7 @@ del Lock
|
||||||
|
|
||||||
def _print(marker, data, scroll=False):
|
def _print(marker, data, scroll=False):
|
||||||
t = time.time() - start_time
|
t = time.time() - start_time
|
||||||
if type(data) == unicode:
|
if is_string(data):
|
||||||
s = marker + ' ' + data
|
s = marker + ' ' + data
|
||||||
else:
|
else:
|
||||||
hexs = strhex(data)
|
hexs = strhex(data)
|
||||||
|
|
|
@ -19,9 +19,6 @@ def init_paths():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if sys.version_info >= (2, 8):
|
|
||||||
sys.exit("Python 3 is not supported by hidconsole.")
|
|
||||||
|
|
||||||
init_paths()
|
init_paths()
|
||||||
from hidapi import hidconsole
|
from hidapi import hidconsole
|
||||||
hidconsole.main()
|
hidconsole.main()
|
||||||
|
|
Loading…
Reference in New Issue