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:
Peter Wu 2013-05-02 22:45:53 +02:00
parent 0f80901bce
commit a6b89b3ea3
2 changed files with 8 additions and 6 deletions

View File

@ -15,12 +15,17 @@ import hidapi
#
#
# no Python 3 support :(
try:
read_packet = raw_input
except NameError:
# Python 3 equivalent of raw_input
read_packet = input
interactive = os.isatty(0)
prompt = '?? Input: ' if interactive else ''
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()
#
@ -33,7 +38,7 @@ del Lock
def _print(marker, data, scroll=False):
t = time.time() - start_time
if type(data) == unicode:
if is_string(data):
s = marker + ' ' + data
else:
hexs = strhex(data)

View File

@ -19,9 +19,6 @@ def init_paths():
if __name__ == '__main__':
if sys.version_info >= (2, 8):
sys.exit("Python 3 is not supported by hidconsole.")
init_paths()
from hidapi import hidconsole
hidconsole.main()