Giter Club home page Giter Club logo

Comments (4)

rene-aguirre avatar rene-aguirre commented on June 24, 2024

@menew, have you seen the show_hids.py example? (https://github.com/rene-aguirre/pywinusb/blob/master/examples/show_hids.py), is this what you need.

Is the issue that you are reporting the fact that __repr__ does not return an unicode object?

Otherwise I don't think managing encodings in __repr__ (as os forcing ascii) is a good idea.

from pywinusb.

menew avatar menew commented on June 24, 2024

@rene-aguirre, thank you for reply!

have you seen the show_hids.py example? (https://github.com/rene-aguirre/pywinusb/blob/master/examples/show_hids.py), is this what you need.

Yes, but passing show_hids() any encoders as output does not affect the situation.

For example, when I execute the following code:

# coding: utf-8

import sys
import codecs
import pywinusb.hid as hid

output = codecs.getwriter('mbcs')(sys.stdout)
hid.core.show_hids(output = output)

I got same UnicodeEncodeError as below, regardless of writer encoding:

Found HID class devices!, writting details...

Traceback (most recent call last):
  File "C:\Users\menew\Desktop\Documents\show_hids.py", line 8, in <module>
    hid.core.show_hids(output = output)
  File "build\bdist.win-amd64\egg\pywinusb\hid\core.py", line 1596, in show_hids
    device_name = str(dev)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 115-129: ordinal not in range(128)

And, if I edited hid.core.HidDevice.__repr__ as this, then show_hids() shows report successfully without specifying output writer.

def __repr__(self):
    # patched for python 2.x
    # (`"%s" % self.product_name` raises UnicodeEncodeError if `product_name` has non-ascii characters)
    return (u"HID device (vID=0x%04x, pID=0x%04x, v=0x%04x); %s; %s, " \
        u"Path: %s" % (self.vendor_id, self.product_id, self.version_number,\
        self.vendor_name, self.product_name, self.device_path)).encode('ascii', 'replace')

I think underlying problem is incompatibility that Python 2 demands __repr__ to return non-unicode object whereas Python 3 demands unicode object. Because of the incompatibility, some version detection code or forcing ascii charset seem necessary to make __repr__() support both Python versions...

from pywinusb.

rene-aguirre avatar rene-aguirre commented on June 24, 2024

"...without specifying output writer"

I think the library has to be encoding transparent. The decoding has to be managed by the application, not the library.

My question, about the "show_hids.py" example is that it actually fails with your device, "as is".

Just run it and let me know if this raises the Unicode error.

Also, when you refer to the japanese locale, is this the system locale (how did you set it?) or the USB device string encoding?

I'd like to reproduce your issue to look for alternatives, would be possible to get a dump of the device that includes string descriptors?

from pywinusb.

rene-aguirre avatar rene-aguirre commented on June 24, 2024

@menew do you have a branch with your changes so issue #36 can be tested?

from pywinusb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.