Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • S Solaar
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 10
    • Issues 10
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 2
    • Merge requests 2
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • pwr-Solaar
  • Solaar
  • Issues
  • #32
Closed
Open
Issue created May 02, 2013 by Administrator@rootContributor

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:

  • read in hidapi/udev.py returns type bytes on Python3 instead of str.
  • Change every check for type(foo) == unicode or type(foo) == str (or isinstance). unicode has gone in Python3, this became str. isinstance('', bytes) is True for python2, but False in python3.
  • Currently bytes are printed verbatim (in hidconsole at least). On Python 2 one could see '\xffX' where python 3 shows b'\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:

  • http://stackoverflow.com/questions/7585435/best-way-to-convert-string-to-bytes-in-python-3
  • http://stackoverflow.com/questions/606191/convert-byte-array-to-python-string
Assignee
Assign to
Time tracking