Consistently use byte/str everywhere
Created by: Lekensteyn
Python2 and python3 differ in the handling of bytes and unicode. In python2, unicode is not equal to str. In Python3, bytes are not equal to str:
$ for v in 2 3; do python$v -c "print(type(u''), type(b''), type(''))";done
(<type 'unicode'>, <type 'str'>, <type 'str'>)
<class 'str'> <class 'bytes'> <class 'str'>
$ for v in 2 3; do echo|python$v -c $'import os\nprint(type(os.read(0, 1)))';done
<type 'str'>
<class 'bytes'>
Todo:
-
readinhidapi/udev.pyreturns typebyteson Python3 instead ofstr. - Change every check for
type(foo) == unicode or type(foo) == str(orisinstance).unicodehas gone in Python3, this becamestr.isinstance('', bytes)isTruefor python2, butFalsein python3. - Currently bytes are printed verbatim (in hidconsole at least). On Python 2 one could see
'\xffX'where python 3 showsb'\xffX'. Changing it to'\xff\x58'would give a more consistent output, but I think you did this to spot text easier in the protocol. Does it matter that the output is different?
Possible helpful resources: