From a6b89b3ea305ffdb4464553b214412001de21ae5 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 2 May 2013 22:45:53 +0200 Subject: [PATCH] Python3 compatibility for hidconsole `type(u'')` is 'str' in Python 3, it was `unicode` on Python 2 (with `unicode_literals` from `__future__`). --- lib/hidapi/hidconsole.py | 11 ++++++++--- tools/hidconsole | 3 --- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/hidapi/hidconsole.py b/lib/hidapi/hidconsole.py index d23beea3..4547c5ec 100644 --- a/lib/hidapi/hidconsole.py +++ b/lib/hidapi/hidconsole.py @@ -15,12 +15,17 @@ import hidapi # # -# no Python 3 support :( -read_packet = raw_input +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) diff --git a/tools/hidconsole b/tools/hidconsole index 6ca49a75..8a0e7902 100755 --- a/tools/hidconsole +++ b/tools/hidconsole @@ -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()